Simple thread pool that executes tasks in a fixed number of worker threads. More...
#include <ThreadPool.h>
Public Types | |
| using | Task = ThreadPoolTask |
Public Member Functions | |
| Result | create (size_t workerThreads) |
| Create a thread pool with the requested number of worker threads. | |
| Result | destroy () |
| Destroy the thread pool created previously with ThreadPool::create. | |
| Result | queueTask (Task &task) |
| Queue a task (that should not be already in use) | |
| Result | waitForAllTasks () |
| Blocks execution until all queued and pending tasks will be fully completed. | |
| Result | waitForTask (Task &task) |
| Blocks execution until all queued and pending tasks will be fully completed. | |
Simple thread pool that executes tasks in a fixed number of worker threads.
This class is not copyable / moveable due to it containing Mutex and Condition variable. Additionally, this class does not allocate any memory by itself, and expects the caller to supply SC::ThreadPool::Task objects.
Example:
Create a thread pool with the requested number of worker threads.
| Result SC::ThreadPool::destroy | ( | ) |
Destroy the thread pool created previously with ThreadPool::create.
| Result SC::ThreadPool::waitForAllTasks | ( | ) |
Blocks execution until all queued and pending tasks will be fully completed.
Blocks execution until all queued and pending tasks will be fully completed.