#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) |
DISPENSO_DLL_ACCESS | ~ThreadPool () |
Static Public Member Functions | |
static void * | operator new (size_t sz) |
static void | operator delete (void *ptr) |
Friends | |
class | ConcurrentTaskSet |
class | TaskSet |
class | TaskSetBase |
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 73 of file thread_pool.h.
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. |
Definition at line 70 of file thread_pool.cpp.
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.
|
inline |
Get the number of threads backing the pool. If called concurrently to resize
, the number returned may be stale.
Definition at line 130 of file thread_pool.h.
Definition at line 223 of file thread_pool.h.
Definition at line 220 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 119 of file thread_pool.h.
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 272 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 285 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 103 of file thread_pool.h.
|
friend |
Definition at line 250 of file thread_pool.h.
Definition at line 251 of file thread_pool.h.
Definition at line 252 of file thread_pool.h.