大网数据广告活动
Windows 系统接口

Thread Pool API

· 52CE 我爱测

The thread pool application programming interface (API) uses an object-based design.

The thread pool application programming interface (API) uses an object-based design. Each of the following objects is represented by a user-mode data structure:

  • A pool object is a set of worker threads that can be used to perform work. Each process can create multiple isolated pools with different characteristics as necessary. There is also a default pool for each process.
  • A clean-up group is associated with a set of callback-generating objects. Functions exist to wait on and release all objects that are members of each clean-up group. This frees the application from keeping track of all the objects it has created.
  • A work object is assigned to a pool and optionally to a clean-up group. It can be posted, causing a worker thread from the pool to execute its callback. A work object can have multiple posts outstanding; each generates a callback. The post operation cannot fail due to lack of resources.
  • A timer object controls the scheduling of callbacks. Each time a timer expires, its callback is posted to its worker pool. Setting a timer cannot fail due to lack of resources.
  • A wait object causes a waiter thread to wait on a waitable handle. After the wait is satisfied or the time-out period expires, the waiter thread posts the wait objects' callback to the wait's worker pool. Setting a wait cannot fail due to lack of resources.
  • An I/O object associates a file handle with the I/O completion port for the thread pool. When an asynchronous I/O operation completes, a worker thread picks up the status of the operation and calls the I/O object's callback.

The following table describes the features of the original and current thread pool APIs.

Feature Original API Current API
Synch RegisterWaitForSingleObject UnregisterWaitEx CloseThreadpoolWait CreateThreadpoolWait SetThreadpoolWait WaitForThreadpoolWaitCallbacks
Work QueueUserWorkItem CloseThreadpoolWork CreateThreadpoolWork SubmitThreadpoolWork TrySubmitThreadpoolCallback WaitForThreadpoolWorkCallbacks
Timer CreateTimerQueue CreateTimerQueueTimer ChangeTimerQueueTimer DeleteTimerQueueTimer DeleteTimerQueueEx CloseThreadpoolTimer CreateThreadpoolTimer IsThreadpoolTimerSet SetThreadpoolTimer WaitForThreadpoolTimerCallbacks
I/O BindIoCompletionCallback CancelThreadpoolIo CloseThreadpoolIo CreateThreadpoolIo StartThreadpoolIo WaitForThreadpoolIoCallbacks
Clean-up group CloseThreadpoolCleanupGroup CloseThreadpoolCleanupGroupMembers CreateThreadpoolCleanupGroup
Pool CloseThreadpool CreateThreadpool SetThreadpoolThreadMaximum SetThreadpoolThreadMinimum
Callback environment DestroyThreadpoolEnvironment InitializeThreadpoolEnvironment SetThreadpoolCallbackCleanupGroup SetThreadpoolCallbackLibrary SetThreadpoolCallbackPool SetThreadpoolCallbackPriority SetThreadpoolCallbackRunsLong
Callback CallbackMayRunLong
Callback clean up DisassociateCurrentThreadFromCallback FreeLibraryWhenCallbackReturns LeaveCriticalSectionWhenCallbackReturns ReleaseMutexWhenCallbackReturns ReleaseSemaphoreWhenCallbackReturns SetEventWhenCallbackReturns

Related topics

Thread Pools

Using the Thread Pool Functions

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 07/14/2025
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。