|
dispenso 1.4.1
A library for task parallelism
|
#include <thread_pool.h>
Public Member Functions | |
| DISPENSO_DLL_ACCESS | ThreadPool (size_t n, size_t poolLoadMultiplier=32) |
| template<class Rep , class Period > | |
| void | setSignalingWake (bool enable, const std::chrono::duration< Rep, Period > &sleepDuration=std::chrono::microseconds(kDefaultSleepLenUs)) |
| DISPENSO_DLL_ACCESS void | resize (ssize_t n) |
| ssize_t | numThreads () const |
| template<typename F > | |
| void | schedule (F &&f) |
| template<typename F > | |
| void | schedule (F &&f, ForceQueuingTag) |
| template<typename Generator > | |
| void | scheduleBulk (size_t count, Generator &&gen) |
| DISPENSO_DLL_ACCESS | ~ThreadPool () |
Friends | |
| class | ConcurrentTaskSet |
| class | TaskSet |
The basic executor for dispenso. It provides typical thread pool functionality, plus allows work stealing by related types (e.g. TaskSet, Future, etc...), which prevents deadlock when waiting for pool-recursive tasks.
Definition at line 72 of file thread_pool.h.
| DISPENSO_DLL_ACCESS dispenso::ThreadPool::ThreadPool | ( | size_t | n, |
| size_t | poolLoadMultiplier = 32 ) |
Construct a thread pool.
| n | The number of threads to spawn at construction. |
| poolLoadMultiplier | A parameter that specifies how overloaded the pool should be before allowing the current thread to self-steal work. |
| DISPENSO_DLL_ACCESS dispenso::ThreadPool::~ThreadPool | ( | ) |
Destruct the pool. This destructor is blocking until all queued work is completed. It is illegal to call the destructor while any other thread makes calls to the pool (as is generally the case with C++ classes).
|
inline |
Get the number of threads backing the pool. If called concurrently to resize, the number returned may be stale.
Definition at line 129 of file thread_pool.h.
|
inline |
Change the number of threads backing the thread pool. This is a blocking and potentially slow operation, and repeatedly resizing is discouraged.
| n | The number of threads in use after call completion |
Definition at line 118 of file thread_pool.h.
|
inline |
Schedule a functor to be executed. If the pool's load factor is high, execution may happen inline by the calling thread.
| f | The functor to be executed. f's signature must match void(). Best performance will come from passing lambdas, other concrete functors, or OnceFunction, but std::function or similarly type-erased objects will also work. |
Definition at line 315 of file thread_pool.h.
|
inline |
Schedule a functor to be executed. The functor will always be queued and executed by pool threads.
| f | The functor to be executed. f's signature must match void(). Best performance will come from passing lambdas, other concrete functors, or OnceFunction, but std::function or similarly type-erased objects will also work. |
Definition at line 329 of file thread_pool.h.
| void dispenso::ThreadPool::scheduleBulk | ( | size_t | count, |
| Generator && | gen ) |
Schedule multiple functors to be executed in bulk. This is more efficient than calling schedule() multiple times when you have many tasks to submit, as it reduces atomic contention and allows for better thread wakeup behavior.
| count | The number of functors to schedule. |
| gen | A generator functor that takes an index and returns a functor to execute. gen(i) will be called for i in [0, count) to produce each task. |
Definition at line 466 of file thread_pool.h.
|
inline |
Enable or disable signaling wake functionality. If enabled, this will try to ensure that threads are woken up proactively when work has not been available and it becomes available. This function is blocking and potentially very slow. Repeated use is discouraged.
| enable | If set true, turns on signaling wake. If false, turns it off. |
| sleepDuration | If enable is true, this is the length of time a thread will wait for a signal before waking up. If enable is false, this is the length of time a thread will sleep between polling. |
Definition at line 102 of file thread_pool.h.
|
friend |
Definition at line 292 of file thread_pool.h.
|
friend |
Definition at line 293 of file thread_pool.h.