windows核心编程笔记第十一章线程池(thewindowsthrea

上传人:工**** 文档编号:455835033 上传时间:2023-12-19 格式:DOC 页数:7 大小:26KB
返回 下载 相关 举报
windows核心编程笔记第十一章线程池(thewindowsthrea_第1页
第1页 / 共7页
windows核心编程笔记第十一章线程池(thewindowsthrea_第2页
第2页 / 共7页
windows核心编程笔记第十一章线程池(thewindowsthrea_第3页
第3页 / 共7页
windows核心编程笔记第十一章线程池(thewindowsthrea_第4页
第4页 / 共7页
windows核心编程笔记第十一章线程池(thewindowsthrea_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《windows核心编程笔记第十一章线程池(thewindowsthrea》由会员分享,可在线阅读,更多相关《windows核心编程笔记第十一章线程池(thewindowsthrea(7页珍藏版)》请在金锄头文库上搜索。

1、windows 核心编程(第五版)笔记第十一章线程池(thewindowsthrea.Windows 核心编程(第五版)笔记 第十一章 线程池 (TheWindows Thread Pool)第十一章 线程池线程池的目的就是为了减少创建和销毁线程的额外开销,利用已经存在的线程多次循环执行多个任务从而提高系统的 处理能力 .线程池会自动地根据内制的算法增加或减少线程池中的线 程或为程序增加新的线程池。1. 异步方法调用异步方法调用有以下两种方法:(1)线程函数原型 (回调函数 )VOID NTAPISimpleCallbackPTP_CALLBACK_INSTANCE pInstance, /

2、See CallbackTermination Actions sectionPVOID pvContext );TrySubmitThreadpoolCallback该函数将线程函数执 行请求发到线程池 ,并将一个 工作项目 添加到线程池的队 列中。注:我们不需要调用 CreateThread函数,线程池中的线程会执行我们的回调函数(2)显示控制 工作项目 CreateThreadpoolWork 创建一个工作项目等待线程函数执SubmitThreadpoolWork 将工作项目提交到线程池中,一个工作项目可以多次提交到 线程池中。WaitForThreadpoolWorkCallbacks

3、行完毕或取消执行线程函数CreateThreadpoolWork 要求的线程函数原型:VOID CALLBACK WorkCallback(PTP_CALLBACK_INSTANCE Instance,PVOID Context,PTP_WORK Work);VOID WaitForThreadpoolWorkCallbacks(PTP_WORK pWork,);2. 时间间隔内调用函数(1)CreateThreadpoolTimer 要求的线程函数原型VOID CALLBACKTimeoutCallback(PTP_CALLBACK_INSTANCE pInstance, / See Cal

4、lbackTermination Actions sectionPVOID pvContext,PTP_TIMER pTimer);(2)步骤CreateThreadpoolTimerSetThreadpoolTimerWaitForThreadpoolTimerCallbacksCloseThreadpoolTimer3. 当内核对象处于 Signal 状态时调用函数 当指定的内核对象变 成 Signal 状态或等待超时,线程池会用户指定的线程函数。之后当内核对象再次 变成 Signal 状态时 ,线程函数不会被调用,除非再次调用 SetThreadpoolWait 注册线程函数。(1)Cr

5、eateThreadpoolWait 要求的线程函数原型VOID CALLBACKWaitCallback(PTP_CALLBACK_INSTANCE pInstance, / See Callback Termination Actions sectionPVOID Context,PTP_WAIT Wait,TP_WAIT_RESULT WaitResult);CreateThreadpoolWait SetThreadpoolWait不允许多次注册同样的Handle,但是我们可以用DuplicateHandle 函数复制一个句柄 然后再注册。WaitForThreadpoolWaitCa

6、llbacksCloseThreadpoolWait4. 当异步 I/O 请求结束后调用函数To be filled5. 回调终结后的操作和私有线程To be filled6. Common APITrySubmitThreadpoolCallbackCreateThreadpoolWorkSubmitThreadpoolWork WaitForThreadpoolWorkCallbacks CloseThreadpoolWorkCreateThreadpoolTimer SetThreadpoolTimerWaitForThreadpoolTimerCallbacks CloseThreadpoolTimerCreateThreadpoolWait SetThreadpoolWaitWaitForThreadpoolWaitCallbacks CloseThreadpoolWaitCallbackMayRunLong DisassociateCurrentThreadFromCallback

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 活动策划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号