flexiblesusy is hosted by Hepforge, IPPP Durham
FlexibleSUSY
flexiblesusy::Thread_pool Class Reference

A pool of threads. More...

#include <thread_pool.hpp>

Collaboration diagram for flexiblesusy::Thread_pool:
Collaboration graph

Public Member Functions

Thread_pooloperator= (const Thread_pool &)=delete
 
Thread_pooloperator= (Thread_pool &&)=delete
 
template<typename Task >
auto run_packaged_task (Task &&task) -> std::future< decltype(task())>
 runs task and returns future More...
 
template<typename Task >
void run_task (Task &&task)
 runs task More...
 
std::size_t size () const
 
 Thread_pool (const Thread_pool &)=delete
 
 Thread_pool (std::size_t pool_size=std::thread::hardware_concurrency())
 
 Thread_pool (Thread_pool &&)=delete
 
 ~Thread_pool ()
 waits for all tasks to finish and closes threads More...
 

Private Attributes

std::condition_variable condition {}
 
std::mutex mutex {}
 
bool stop {false}
 
std::queue< std::function< void()> > tasks {}
 
std::vector< std::thread > threads {}
 

Detailed Description

A pool of threads.

Thread_pool represents a collection of threads. Tasks (callables) can be added to an internal queue. The tasks will be executed as soon as there is an idle thread. The destructor of the Thread_pool will wait until all tasks are finished and the queue is empty.

Parameters
pool_sizenumber of threads in the pool

Definition at line 47 of file thread_pool.hpp.

Constructor & Destructor Documentation

◆ Thread_pool() [1/3]

flexiblesusy::Thread_pool::Thread_pool ( std::size_t  pool_size = std::thread::hardware_concurrency())
inlineexplicit

Definition at line 49 of file thread_pool.hpp.

References threads, and VERBOSE_MSG.

◆ Thread_pool() [2/3]

flexiblesusy::Thread_pool::Thread_pool ( const Thread_pool )
delete

◆ Thread_pool() [3/3]

flexiblesusy::Thread_pool::Thread_pool ( Thread_pool &&  )
delete

◆ ~Thread_pool()

flexiblesusy::Thread_pool::~Thread_pool ( )
inline

waits for all tasks to finish and closes threads

Definition at line 78 of file thread_pool.hpp.

References flexiblesusy::Electroweak_constants::anonymous_namespace{ew_input.hpp}::e, ERROR, and stop.

Member Function Documentation

◆ operator=() [1/2]

Thread_pool & flexiblesusy::Thread_pool::operator= ( const Thread_pool )
delete

◆ operator=() [2/2]

Thread_pool & flexiblesusy::Thread_pool::operator= ( Thread_pool &&  )
delete

◆ run_packaged_task()

template<typename Task >
auto flexiblesusy::Thread_pool::run_packaged_task ( Task &&  task) -> std::future<decltype(task())>
inline

runs task and returns future

Definition at line 97 of file thread_pool.hpp.

◆ run_task()

template<typename Task >
void flexiblesusy::Thread_pool::run_task ( Task &&  task)
inline

runs task

Definition at line 120 of file thread_pool.hpp.

◆ size()

std::size_t flexiblesusy::Thread_pool::size ( ) const
inline

Definition at line 133 of file thread_pool.hpp.

Member Data Documentation

◆ condition

std::condition_variable flexiblesusy::Thread_pool::condition {}
private

Definition at line 139 of file thread_pool.hpp.

◆ mutex

std::mutex flexiblesusy::Thread_pool::mutex {}
private

Definition at line 138 of file thread_pool.hpp.

◆ stop

bool flexiblesusy::Thread_pool::stop {false}
private

Definition at line 140 of file thread_pool.hpp.

◆ tasks

std::queue<std::function<void()> > flexiblesusy::Thread_pool::tasks {}
private

Definition at line 137 of file thread_pool.hpp.

◆ threads

std::vector<std::thread> flexiblesusy::Thread_pool::threads {}
private

Definition at line 136 of file thread_pool.hpp.

Referenced by Thread_pool().


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