quickpool  1.5.0
An easy-to-use, header-only work stealing thread pool in C++11
Classes | Functions
quickpool Namespace Reference

quickpool namespace More...

Classes

class  ThreadPool
 A work stealing thread pool. More...
 

Functions

template<class Function , class... Args>
void push (Function &&f, Args &&... args)
 Free-standing functions (main API) 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. Has no effect when not called from main thread.
 
bool done ()
 checks whether all globel jobs are done.
 
void set_active_threads (size_t threads)
 sets the number of active worker threads in the global thread pool. More...
 
size_t get_active_threads ()
 retrieves the number of active worker threads in the global thread pool.
 
template<class UnaryFunction >
void parallel_for (int begin, int end, UnaryFunction &&f)
 computes an index-based parallel for loop. More...
 
template<class Items , class UnaryFunction >
void parallel_for_each (Items &items, UnaryFunction &&f)
 computes a iterator-based parallel for loop. More...
 

Detailed Description

quickpool namespace

Function Documentation

◆ async()

template<class Function , class... Args>
auto quickpool::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 1023 of file quickpool.hpp.

◆ parallel_for()

template<class UnaryFunction >
void quickpool::parallel_for ( int  begin,
int  end,
UnaryFunction &&  f 
)
inline

computes an index-based parallel for loop.

Waits until all tasks have finished, unless called from a thread that didn't create the pool. If this is taken into account, parallel loops can be nested.

Parameters
beginfirst index of the loop.
endthe loop runs in the range [begin, end).
fa function taking int argument (the 'loop body').

Definition at line 1072 of file quickpool.hpp.

◆ parallel_for_each()

template<class Items , class UnaryFunction >
void quickpool::parallel_for_each ( Items &  items,
UnaryFunction &&  f 
)
inline

computes a iterator-based parallel for loop.

Waits until all tasks have finished, unless called from a thread that didn't create the pool. If this is taken into account, parallel loops can be nested.

Parameters
itemsan object allowing for std::begin() and std::end().
ffunction to be applied as f(*it) for the iterator in the range [begin, end) (the 'loop body').

Definition at line 1089 of file quickpool.hpp.

◆ push()

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

Free-standing functions (main API)

push a job to the global thread pool.

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

Definition at line 1010 of file quickpool.hpp.

◆ set_active_threads()

void quickpool::set_active_threads ( size_t  threads)
inline

sets the number of active worker threads in the global thread pool.

Parameters
threadsthe number of worker threads. Has no effect when not called from main thread.

Definition at line 1048 of file quickpool.hpp.