#include <thread_pool.h>
|
| 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) |
| |
| DISPENSO_DLL_ACCESS | ~ThreadPool () |
| |
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.
- Examples
- future_example.cpp, pipeline_example.cpp, and task_set_example.cpp.
Definition at line 74 of file thread_pool.h.
◆ ThreadPool()
| dispenso::ThreadPool::ThreadPool |
( |
size_t | n, |
|
|
size_t | poolLoadMultiplier = 32 ) |
Construct a thread pool.
- Parameters
-
| 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. |
Definition at line 70 of file thread_pool.cpp.
◆ ~ThreadPool()
| 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).
Definition at line 197 of file thread_pool.cpp.
◆ numThreads()
| ssize_t dispenso::ThreadPool::numThreads |
( |
| ) |
const |
|
inline |
Get the number of threads backing the pool. If called concurrently to resize, the number returned may be stale.
- Returns
- The current number of threads backing the pool.
Definition at line 131 of file thread_pool.h.
◆ operator delete()
| static void dispenso::ThreadPool::operator delete |
( |
void * | ptr | ) |
|
|
inlinestatic |
◆ operator new()
| static void * dispenso::ThreadPool::operator new |
( |
size_t | sz | ) |
|
|
inlinestatic |
◆ resize()
| DISPENSO_DLL_ACCESS void dispenso::ThreadPool::resize |
( |
ssize_t | n | ) |
|
|
inline |
Change the number of threads backing the thread pool. This is a blocking and potentially slow operation, and repeatedly resizing is discouraged.
- Parameters
-
| n | The number of threads in use after call completion |
Definition at line 120 of file thread_pool.h.
◆ schedule() [1/2]
template<typename F >
| void dispenso::ThreadPool::schedule |
( |
F && | f | ) |
|
|
inline |
Schedule a functor to be executed. If the pool's load factor is high, execution may happen inline by the calling thread.
- Parameters
-
| 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 273 of file thread_pool.h.
◆ schedule() [2/2]
Schedule a functor to be executed. The functor will always be queued and executed by pool threads.
- Parameters
-
| 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 286 of file thread_pool.h.
◆ setSignalingWake()
template<class Rep , class Period >
| void dispenso::ThreadPool::setSignalingWake |
( |
bool | enable, |
|
|
const std::chrono::duration< Rep, Period > & | sleepDuration = std::chrono::microseconds(kDefaultSleepLenUs) ) |
|
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.
- Parameters
-
| 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. |
- Note
- It is highly recommended to leave signaling wake enabled on Windows platforms, as sleeping/polling tends to perform poorly for intermittent workloads. For Mac/Linux platforms, it is okay to enable signaling wake, particularly if you wish to set a longer expected duration between work. If signaling wake is disabled, ensure sleepDuration is small (e.g. 200us) for best performance. Most users will not need to call this function, as defaults are reasonable.
Definition at line 104 of file thread_pool.h.
◆ ConcurrentTaskSet
◆ TaskSet
◆ TaskSetBase
The documentation for this class was generated from the following files: