quickpool  0.2.0
An easy-to-use, header-only work stealing thread pool in C++11
Public Member Functions | Static Public Member Functions | List of all members
quickpool::ThreadPool Class Reference

A work stealing thread pool. More...

#include <quickpool.hpp>

Public Member Functions

 ThreadPool ()
 constructs a thread pool with as many workers as there are cores.
 
 ThreadPool (size_t n_workers)
 
 ThreadPool (ThreadPool &&)=delete
 
 ThreadPool (const ThreadPool &)=delete
 
ThreadPooloperator= (const ThreadPool &)=delete
 
ThreadPooloperator= (ThreadPool &&other)=delete
 
template<class Function , class... Args>
void push (Function &&f, Args &&... args)
 pushes a job to the thread pool. More...
 
template<class Function , class... Args>
auto async (Function &&f, Args &&... args) -> std::future< decltype(f(args...))>
 executes a job asynchronously the global thread pool. More...
 
void wait ()
 waits for all jobs currently running on the global thread pool.
 

Static Public Member Functions

static ThreadPoolglobal_instance ()
 returns a reference to the global thread pool instance.
 

Detailed Description

A work stealing thread pool.

Definition at line 330 of file quickpool.hpp.

Constructor & Destructor Documentation

◆ ThreadPool()

quickpool::ThreadPool::ThreadPool ( size_t  n_workers)
inlineexplicit

constructs a thread pool.

Parameters
n_workersnumber of worker threads to create; defaults to number of available (virtual) hardware cores.

Definition at line 341 of file quickpool.hpp.

Member Function Documentation

◆ async()

template<class Function , class... Args>
auto quickpool::ThreadPool::async ( Function &&  f,
Args &&...  args 
) -> std::future<decltype(f(args...))>
inline

executes a job asynchronously the global thread pool.

Parameters
fa function.
args(optional) arguments passed to f.
Returns
A std::future for the task. Call future.get() to retrieve the results at a later point in time (blocking).

Definition at line 399 of file quickpool.hpp.

◆ push()

template<class Function , class... Args>
void quickpool::ThreadPool::push ( Function &&  f,
Args &&...  args 
)
inline

pushes a job to the thread pool.

Parameters
fa function.
args(optional) arguments passed to f.

Definition at line 384 of file quickpool.hpp.


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