A thread pool contains 1 or more worker threads which accept thread_pool_task lambadas into a queue, which is processed in-order by whichever thread is free.
More...
#include <thread_pool.h>
A thread pool contains 1 or more worker threads which accept thread_pool_task lambadas into a queue, which is processed in-order by whichever thread is free.
◆ thread_pool()
dpp::thread_pool::thread_pool |
( |
class cluster * |
creator, |
|
|
size_t |
num_threads = std::thread::hardware_concurrency() |
|
) |
| |
|
explicit |
Create a new priority thread pool.
- Parameters
-
creator | creating cluster (for logging) |
num_threads | number of threads in the pool |
◆ ~thread_pool()
dpp::thread_pool::~thread_pool |
( |
| ) |
|
◆ enqueue()
Enqueue a new task to the thread pool.
- Parameters
-
◆ cv
std::condition_variable dpp::thread_pool::cv |
Condition variable to notify for new tasks to run.
◆ queue_mutex
std::mutex dpp::thread_pool::queue_mutex |
Mutex for accessing the priority queue.
◆ stop
bool dpp::thread_pool::stop {false} |
True if the thread pool is due to stop.
◆ tasks
Priority queue of tasks to be executed.
◆ threads
std::vector<std::thread> dpp::thread_pool::threads |
Threads that comprise the thread pool.