![]() |
D++ (DPP)
C++ Discord API Bot Library
|
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...
Public Member Functions | |
thread_pool (class cluster *creator, size_t num_threads=std::thread::hardware_concurrency()) | |
Create a new priority thread pool. More... | |
~thread_pool () | |
Destroy the thread pool. More... | |
void | enqueue (thread_pool_task task) |
Enqueue a new task to the thread pool. More... | |
Public Attributes | |
std::vector< std::thread > | threads |
Threads that comprise the thread pool. More... | |
std::priority_queue< thread_pool_task, std::vector< thread_pool_task >, thread_pool_task_comparator > | tasks |
Priority queue of tasks to be executed. More... | |
std::mutex | queue_mutex |
Mutex for accessing the priority queue. More... | |
std::condition_variable | cv |
Condition variable to notify for new tasks to run. More... | |
bool | stop {false} |
True if the thread pool is due to stop. More... | |
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.
|
explicit |
Create a new priority thread pool.
creator | creating cluster (for logging) |
num_threads | number of threads in the pool |
dpp::thread_pool::~thread_pool | ( | ) |
Destroy the thread pool.
void dpp::thread_pool::enqueue | ( | thread_pool_task | task | ) |
Enqueue a new task to the thread pool.
task | task to enqueue |
std::condition_variable dpp::thread_pool::cv |
Condition variable to notify for new tasks to run.
std::mutex dpp::thread_pool::queue_mutex |
Mutex for accessing the priority queue.
bool dpp::thread_pool::stop {false} |
True if the thread pool is due to stop.
std::priority_queue<thread_pool_task, std::vector<thread_pool_task>, thread_pool_task_comparator> dpp::thread_pool::tasks |
Priority queue of tasks to be executed.
std::vector<std::thread> dpp::thread_pool::threads |
Threads that comprise the thread pool.