General Utility Library for C++14  2.11
Classes | Enumerations | Functions
gul14/ThreadPool.h

Detailed Description

A thread pool and task queue.

Classes

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

Enumerations

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

Functions

std::shared_ptr< ThreadPoolgul14::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. More...
 

Enumeration Type Documentation

◆ TaskState

enum gul14::TaskState
strong

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> gul14::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.
Examples
thread_pool.cc.

References gul14::ThreadPool::capacity(), and gul14::ThreadPool::make_shared().