General Utility Library for C++17 25.4.1
Classes | Enumerations | Functions
gul17/ThreadPool.h

Detailed Description

A thread pool and task queue.

Classes

class  gul17::ThreadPool
 A pool of worker threads with a task queue. More...
 

Enumerations

enum class  gul17::TaskState { gul17::TaskState::pending , gul17::TaskState::running , gul17::TaskState::complete , gul17::TaskState::canceled }
 An enum describing the state of an individual task. More...
 

Functions

std::shared_ptr< ThreadPoolgul17::make_thread_pool (std::size_t num_threads, std::size_t capacity=ThreadPool::default_capacity)
 Create a thread pool with the desired number of threads and the specified capacity for queuing tasks.
 

Enumeration Type Documentation

◆ TaskState

An enum describing the state of an individual task.

Enumerator
pending 

The task is waiting to be started.

running 

The task is currently being executed.

complete 

The task has finished (successfully or by throwing an exception).

canceled 

The task was removed from the queue before it was started.

Function Documentation

◆ make_thread_pool()

std::shared_ptr< ThreadPool > gul17::make_thread_pool ( std::size_t  num_threads,
std::size_t  capacity = ThreadPool::default_capacity 
)
inline

Create a thread pool with the desired number of threads and the specified capacity for queuing tasks.

The thread pool is allocated in a shared pointer, which is necessary so that task handles can access the pool safely. A ThreadPool cannot be constructed directly.

Returns
a shared pointer to the created ThreadPool object.

References gul17::bit_set(), gul17::ThreadPool::capacity(), and gul17::ThreadPool::make_shared().