带优先级的多任务管理模块(C)
多任务多线程管理模块,任务有优先级,一个任务执行完毕,按照优先级高低执行另一个任务 1)如何使用: 1. 声明一个HashTaskList,或在栈上动态获取; 2. 调用InitTaskList初始化上一步的HashTaskList 3. 调用StartTaskManager开始启动任务管理 ***** 对于一个HashTaskList而言,以上2个函数只调用一次 4. 调用ApplyTask向第一步得到的结构对象添加任务,每调用一次添一个任务 2)如 何终止任务管理功能: 1. 程序结束,终止程序既停止管理并且释放所有资源,请看2).2括号的内容 2. 调用某个函数,这个功能未写(考虑到模块作为服务运行,不需要终止任务管理的函数) 需要取消所有1v1管理线程,在此需要一个列表保存这些线程的ID 需要清理表当中的互斥锁和信号变量,如果1).1.是动态分配,要释放 3)关于改进: 1. 回收资源的线程和TaskList reclaim[LEVEL_ARRAY_LIMIT];是可以省掉的 但考虑到模块功能的延伸: 如果任务执行失败,先移动到某个地方,过段时间在放回来重试,等等... 其实还有很多可能用到它的地方...所以,依旧保留 2. 有多少个任务可以并发管理目前是固定的 其实可添加一个对StartTaskManager所生成的线程管理的数据结构 这样就能动态的增加或减少任务管理的1v1线程 ***** 可事实上我并不想做这个管理的东西在里面 ***** 没有必要,对提供服务的程序而言这东西一般是固定不变的 ********************************************* 1) How to use: 1. Declare a HashTaskList, or dynamic access stack; 2. Call the initialization of step HashTaskList InitTaskList 3. StartTaskManager started calling the task manager ***** For a HashTaskList, the above two functions called only once 4. Call ApplyTask get to the first structure of an object to add the task, each call to add a task 2) how to terminate the task management functions: 1. End of the process, terminate the program only to stop and release all resources management, see 2) .2 contents of brackets 2. Call a function, this function does not write (taking into account the module as a service and does not require termination of the task management function) One to One managed to cancel all the threads, a list needed in this thread ID to save the Need to clean up the table among the mutex and signal variables, if 1) .1. Is dynamically allocated, to be released 3) on the improvement of: 1. Recycling resources thread and TaskList reclaim [LEVEL_ARRAY_LIMIT]; is to save the But taking into account the extension module function: If the task fails, the first move to a place, over time retry the put back, and so on ... There are many possible places to use it ... so, still retained 2. How many tasks can be complicated to manage the current is fixed In fact, you can add an StartTaskManager generated data structure thread management This can increase or decrease in the dynamic task management in the 1v1 thread ***** Can be a matter of fact I do not want to do this management stuff in there ***** Unnecessary procedures on service delivery in terms of these things are generally fixed
用户评论
代码不错,感谢分享!!!