parallel-cellular-automata
Framework for building parallel cellular automata.
Public Member Functions | List of all members
ca::Threadpool Class Reference

Work-stealing threadpool. More...

#include <threadpool.hpp>

Public Member Functions

 Threadpool (unsigned nw=0)
 Construct a new Threadpool object. More...
 
 ~Threadpool ()
 Destroy the Threadpool object.
 
size_t get_number_workers () const
 Get the number of worker threads. More...
 
template<class F , class... Args>
auto submit (F &&f, Args &&...args) -> std::future< typename std::result_of< F(Args...)>::type >
 Submit work to the threadpool. This function takes a function and its arguments and returns a future that will contain the return value of the function. This can be used to wait for the threadpool to run the task. More...
 

Detailed Description

Work-stealing threadpool.

Constructor & Destructor Documentation

◆ Threadpool()

ca::Threadpool::Threadpool ( unsigned  nw = 0)

Construct a new Threadpool object.

Parameters
nwnumber of workers. If 0 hardwareconcurrency is used. (default 0)

Member Function Documentation

◆ get_number_workers()

size_t ca::Threadpool::get_number_workers ( ) const

Get the number of worker threads.

Returns
size_t the number of worker threads.

◆ submit()

template<class F , class... Args>
auto ca::Threadpool::submit ( F &&  f,
Args &&...  args 
) -> std::future<typename std::result_of<F(Args...)>::type>
inline

Submit work to the threadpool. This function takes a function and its arguments and returns a future that will contain the return value of the function. This can be used to wait for the threadpool to run the task.

Template Parameters
Ffunction type.
Argsargs type.
Parameters
ffunction to execute.
argsargument to pass to the function.
Returns
std::future<typename std::result_of<F(Args...)>::type> future that will contain the result of the function.

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