D++ (DPP)
C++ Discord API Bot Library
dpp::thread_pool Struct Reference

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>

+ Collaboration diagram for dpp::thread_pool:

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_comparatortasks
 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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ 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
creatorcreating cluster (for logging)
num_threadsnumber of threads in the pool

◆ ~thread_pool()

dpp::thread_pool::~thread_pool ( )

Destroy the thread pool.

Member Function Documentation

◆ enqueue()

void dpp::thread_pool::enqueue ( thread_pool_task  task)

Enqueue a new task to the thread pool.

Parameters
tasktask to enqueue

Member Data Documentation

◆ 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

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.

◆ threads

std::vector<std::thread> dpp::thread_pool::threads

Threads that comprise the thread pool.

D++ Library version 10.0.35D++ Library version 10.0.34D++ Library version 10.0.33D++ Library version 10.0.32D++ Library version 10.0.31D++ Library version 10.0.30D++ Library version 10.0.29D++ Library version 10.0.28D++ Library version 10.0.27D++ Library version 10.0.26D++ Library version 10.0.25D++ Library version 10.0.24D++ Library version 10.0.23D++ Library version 10.0.22D++ Library version 10.0.21D++ Library version 10.0.20D++ Library version 10.0.19D++ Library version 10.0.18D++ Library version 10.0.17D++ Library version 10.0.16D++ Library version 10.0.15D++ Library version 10.0.14D++ Library version 10.0.13D++ Library version 10.0.12D++ Library version 10.0.11D++ Library version 10.0.10D++ Library version 10.0.9D++ Library version 10.0.8D++ Library version 10.0.7D++ Library version 10.0.6D++ Library version 10.0.5D++ Library version 10.0.4D++ Library version 10.0.3D++ Library version 10.0.2D++ Library version 10.0.1D++ Library version 10.0.0D++ Library version 9.0.19D++ Library version 9.0.18D++ Library version 9.0.17D++ Library version 9.0.16D++ Library version 9.0.15D++ Library version 9.0.14D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0