Encapsulate a trivial thread pool. More...
#include <DwmThreadPool.hh>
Public Member Functions | |
| ThreadPool () | |
| Constructs the thread pool and starts the threads. | |
| bool | Start () |
| Starts the threads. | |
| void | AddTask (F fn, Args ...args) |
| Adds a task to be executed by the thread pool. | |
| void | Stop () |
| Stops the threads. | |
| void | ClearTasks () |
| Clears all the tasks from the task queue. | |
| ~ThreadPool () | |
| Destructor. | |
Encapsulate a trivial thread pool.
N is the number of threads and F is a functor type that takes Args when invoked.
Work is added to the pool via AddTask().
|
inline |
Adds a task to be executed by the thread pool.
fn is a function object and args are the arguments to the function.
|
inline |
Clears all the tasks from the task queue.
May be useful if you want to Stop() without waiting for queued tasks to complete.
|
inline |
Starts the threads.
Returns true on success, false on failure. A failure indicates that the threads had not been joined (i.e. Stop() had not been called).
|
inline |
Stops the threads.
Note that we will wait for all remaining tasks to be completed.