WorkerPool Class Reference
A pool of worker threads that do stuff in parallel. More...
#include <WorkerPool.hh>
Public Member Functions | |
WorkerPool (const unsigned int _minThreadCount=1u) | |
Creates worker threads. The number of worker threads is determined by max(std::thread::hardware_concurrency, _minThreadCount). More... | |
~WorkerPool () | |
closes worker threads More... | |
void | AddWork (std::function< void()> _work, std::function< void()> _cb=std::function< void()>()) |
Adds work to the worker pool with optional callback. More... | |
bool | WaitForResults (const Time &_timeout=Time::Zero) |
Waits until all work is done and threads are idle. More... | |
Detailed Description
A pool of worker threads that do stuff in parallel.
Constructor & Destructor Documentation
◆ WorkerPool()
|
explicit |
Creates worker threads. The number of worker threads is determined by max(std::thread::hardware_concurrency, _minThreadCount).
- Parameters
-
[in] _minThreadCount The minimum number of threads to create in the pool. A value of zero is converted to a value of 1.
- Note
- It's not recommended to set _minThreadCount greater than std::thread::hardware_concurrency.
◆ ~WorkerPool()
~WorkerPool | ( | ) |
closes worker threads
Member Function Documentation
◆ AddWork()
void AddWork | ( | std::function< void()> | _work, |
std::function< void()> | _cb = std::function< void()>() |
||
) |
Adds work to the worker pool with optional callback.
- Parameters
-
[in] _work function to do one piece of work [in] _cb optional callback when the work is done
- Remarks
- Typical work is a function bound with arguments. It must
◆ WaitForResults()
bool WaitForResults | ( | const Time & | _timeout = Time::Zero | ) |
Waits until all work is done and threads are idle.
- Parameters
-
[in] _timeout How long to wait, default to forever
- Returns
- true if all work was finished
- Remarks
- The return value can be false even when waiting forever if
The documentation for this class was generated from the following file: