![]() |
LibraryLink Utilities
3.0.1
Modern C++ wrapper over LibraryLink and WSTP
|
Thread pool class with support of per-thread queues and work stealing.
Based on A. Williams "C++ Concurrency in Action" 2nd Edition, chapter 9.
| PoolQueue | - any threadsafe queue class that provides push and tryPop methods |
| LocalQueue | - any threadsafe queue class that provides push, tryPop and trySteal methods |
Inheritance diagram for LLU::Async::GenericThreadPool< PoolQueue, LocalQueue >:
Collaboration diagram for LLU::Async::GenericThreadPool< PoolQueue, LocalQueue >:#include <ThreadPool.h>
Public Types | |
| using | TaskType = typename PoolQueue::value_type |
| Type of the tasks processed by the Queue. More... | |
Public Member Functions | |
| GenericThreadPool () | |
| Create a GenericThreadPool with the default number of threads (equal to the hardware concurrency) More... | |
| GenericThreadPool (unsigned threadCount) | |
| Create a GenericThreadPool with given number of threads. More... | |
| GenericThreadPool (const GenericThreadPool &)=delete | |
| GenericThreadPool & | operator= (const GenericThreadPool &)=delete |
| GenericThreadPool (GenericThreadPool &&)=delete | |
| GenericThreadPool & | operator= (GenericThreadPool &&)=delete |
| ~GenericThreadPool () | |
| Destructor sets the "done" flag and notifies all paused threads. More... | |
| template<typename FunctionType , typename... Args> | |
| std::future< std::invoke_result_t< FunctionType, Args... > > | submit (FunctionType &&f, Args &&... args) |
| Main function of the pool which accepts tasks to be evaluated by the worker threads. More... | |
| void | runPendingTask () |
| This is the function that each worker thread runs in a loop. More... | |
| void | checkPause () |
| This is the function worker threads will call to see if the work has been paused. More... | |
| void | pause () noexcept |
| Signal to pause work. More... | |
| void | resume () noexcept |
| Signal to resume work and notify waiting worker threads. More... | |
| using LLU::Async::GenericThreadPool< PoolQueue, LocalQueue >::TaskType = typename PoolQueue::value_type |
Type of the tasks processed by the Queue.
|
inline |
Create a GenericThreadPool with the default number of threads (equal to the hardware concurrency)
|
inlineexplicit |
Create a GenericThreadPool with given number of threads.
| threadCount | - requested number of threads in the pool |
|
inline |
Destructor sets the "done" flag and notifies all paused threads.
Worker threads are joined in the destructor of Async::ThreadJoiner member
|
inlineinherited |
This is the function worker threads will call to see if the work has been paused.
If it has, they will wait on the condition variable.
|
inlinenoexceptinherited |
Signal to pause work.
|
inlinenoexceptinherited |
Signal to resume work and notify waiting worker threads.
|
inline |
This is the function that each worker thread runs in a loop.
|
inline |
Main function of the pool which accepts tasks to be evaluated by the worker threads.
A task is simply a deferred evaluation of a function call.
| FunctionType | - type of the function to be called in a worker thread |
| Args | - argument types of the submitted task |
| f | - function to be called as the task |
| args | - argument to the function call |
f on args