Asterisk - The Open Source Telephony Project GIT-master-77d630f
API providing queued task execution across threads.

The taskpool API is a specialized API for the queueing of tasks in a synchronous or asynchronous manner, to be executed across a pool of threads. For cases where serialization is needed a serializer API is also provided ensuring that tasks queued to the serializer are executed in a serialized fashion within the taskpool.

On creation of a taskpool various options can be set and used to control the operation of the pool. This includes how many taskprocessors are present, whether the pool can grow, whether the pool can shrink, and how long idle taskprocessors should exist before being terminated. This provides flexibility based on the specific needs of the user of the taskpool and the environment.

The queueing of tasks to the taskpool is done using a selector. The selector examines the available taskprocessors and decides which one to queue the task to. This operation can also examine the state of the pool to see if it needs to grow and if enabled and possible does so.

The taskpool API is preferred for many cases over the use of the threadpool due to the far lower overhead involved. Taskpools require no additional thread or task queue for management of the pool itself and the act of queueing tasks, the most common operation, is written to be as simple and minimal as possible. Threadpools are best used for long running tasks and operations.