![]() |
LibraryLink Utilities
3.0.1
Modern C++ wrapper over LibraryLink and WSTP
|
Simple thread pool class with a single queue.
Threads block on the queue if there is no work to do.
| Queue | - any threadsafe queue class that provides push and waitPop methods |
#include <ThreadPool.h>
Public Types | |
| using | TaskType = typename Queue::value_type |
| Type of the tasks processed by the Queue. More... | |
Public Member Functions | |
| BasicThreadPool () | |
| Create a BasicThreadPool with the default number of threads (equal to the hardware concurrency) More... | |
| BasicThreadPool (unsigned threadCount) | |
| Create a BasicThreadPool with given number of threads. More... | |
| BasicThreadPool (const BasicThreadPool &)=delete | |
| BasicThreadPool & | operator= (const BasicThreadPool &)=delete |
| BasicThreadPool (BasicThreadPool &&)=delete | |
| BasicThreadPool & | operator= (BasicThreadPool &&)=delete |
| ~BasicThreadPool () | |
| Destructor sets the "done" flag and unblocks all blocked threads by queuing a proper number of special tasks. 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... | |
| using LLU::Async::BasicThreadPool< Queue >::TaskType = typename Queue::value_type |
Type of the tasks processed by the Queue.
|
inline |
Create a BasicThreadPool with the default number of threads (equal to the hardware concurrency)
|
inlineexplicit |
Create a BasicThreadPool with given number of threads.
| threadCount | - requested number of threads in the pool |
|
inline |
Destructor sets the "done" flag and unblocks all blocked threads by queuing a proper number of special tasks.
Worker threads are joined in the destructor of Async::ThreadJoiner member
|
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