IAtari
Genetic algorithm generating AI capable to play Atari2600 games.
Utils::ThreadPool Class Reference

An implementation of Thread pool. More...

#include <ThreadPool.h>

Public Member Functions

 ThreadPool ()=default
 Default constructor. More...
 
 ~ThreadPool ()
 Default destructor. More...
 
void initialize (std::size_t)
 Create worker threads. More...
 
void add_thread (std::function< void()> initializer)
 Add an extra thread. More...
 
auto add_task (F &&f, Args &&... args) -> std::future< typename std::result_of< F(Args...)>::type >
 Add a task to the thread. More...
 

Private Attributes

std::vector< std::thread > m_threads
 
std::queue< std::function< void()> > m_tasks
 
std::mutex m_mutex
 
std::condition_variable m_condvar
 
bool m_exit {false}
 

Detailed Description

An implementation of Thread pool.

Authors
Jakob Progsch, Václav Zeman

Constructor & Destructor Documentation

◆ ThreadPool()

Utils::ThreadPool::ThreadPool ( )
default

Default constructor.

◆ ~ThreadPool()

Utils::ThreadPool::~ThreadPool ( )
inline

Default destructor.

Member Function Documentation

◆ add_task()

auto Utils::ThreadPool::add_task ( F &&  f,
Args &&...  args 
) -> std::future<typename std::result_of<F(Args...)>::type>

Add a task to the thread.

Parameters
fAn object f
argsA list of arguments
Returns
A future object

◆ add_thread()

void Utils::ThreadPool::add_thread ( std::function< void()>  initializer)
inline

Add an extra thread.

Parameters
initializerAn initializer called before doing anything so that user can initialize per-thread data structures

◆ initialize()

void Utils::ThreadPool::initialize ( std::size_t  )
inline

Create worker threads.

Parameters
threads(Optional) The number of threads

Member Data Documentation

◆ m_condvar

std::condition_variable Utils::ThreadPool::m_condvar
private

◆ m_exit

bool Utils::ThreadPool::m_exit {false}
private

◆ m_mutex

std::mutex Utils::ThreadPool::m_mutex
private

◆ m_tasks

std::queue<std::function<void()> > Utils::ThreadPool::m_tasks
private

◆ m_threads

std::vector<std::thread> Utils::ThreadPool::m_threads
private

The documentation for this class was generated from the following file: