Class ThreadPool

Class Documentation

class ThreadPool

Implements a thread pool with a fixed number of threads.

Public Functions

explicit ThreadPool(size_t thread_count = std::max(1u, std::thread::hardware_concurrency()))

Creates a new thread pool with the a number of workers.

Parameters:

thread_count – number of worker threads

ThreadPool(ThreadPool const &other) = delete
ThreadPool &operator=(ThreadPool const &other) = delete
~ThreadPool()

Destructor, ensuring all threads terminate.

void wait_all()

Waits for all work to be complete.

template<typename Callable, typename ...Args>
std::future<std::result_of_t<Callable(Args...)>> add_task(Callable &&callable, Args&&... args)

Adds a callable task to the task queue.

Parameters:
  • callable – the executable task

  • args – the additional arguments for the task

Returns:

std::future containing the result of the computation