libabigail
Worker Threads

Libabigail's implementation of Thread Pools. More...

Libabigail's implementation of Thread Pools.

The main interface of this pattern is a queue of tasks to be performed. Associated to that queue are a set of worker threads (these are native posix threads) that sits there, idle, until at least one task is added to the queue.

When a task is added to the queue, one thread is woken up, picks the task, removes it from the queue, and executes the instructions it carries. We say the worker thread performs the task.

When the worker thread is done performing the task, the performed task is added to another queue, named as the "done queue". Then the thread looks at the queue of tasks to be performed again, and if there is at least one task in that queue, the same process as above is done. Otherwise, the thread blocks, waiting for a new task to be added to the queue.

By default, the number of worker threads is equal to the number of execution threads advertised by the underlying processor.

Note that the user of the queue can either wait for all the tasks to be performed by the pool of threads,and them stop them, get the vector of done tasks and proceed to whatever computation she may need next.

Or she can choose to be asynchronously notified whenever a task is performed and added to the "done queue".