| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
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:
[legend]

## Public Member Functions

| thread_pool (class cluster *creator, size_t num_threads=std::thread::hardware_concurrency())
| Create a new priority thread pool.
| ~thread_pool ()
| Destroy the thread pool.
void | enqueue (thread_pool_task task)
| Enqueue a new task to the thread pool.

## Public Attributes

std::condition_variable | cv
| Condition variable to notify for new tasks to run.
std::mutex | queue_mutex
| Mutex for accessing the priority queue.
bool | 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 > | tasks
| Priority queue of tasks to be executed.
std::vector< std::thread > | threads
| Threads that comprise the thread pool.

## 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

  creator | creating cluster (for logging)
  num_threads | number 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

  task | task 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 9.0.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0