A work stealing thread pool.
More...
#include <quickpool.hpp>
|
| | ThreadPool (size_t threads=sched::num_cores_avail()) |
| | constructs a thread pool. More...
|
| |
|
| ThreadPool (ThreadPool &&)=delete |
| |
|
| ThreadPool (const ThreadPool &)=delete |
| |
|
ThreadPool & | operator= (const ThreadPool &)=delete |
| |
|
ThreadPool & | operator= (ThreadPool &&other)=delete |
| |
| void | set_active_threads (size_t threads) |
| | sets the number of active worker threads in the thread pool. More...
|
| |
|
size_t | get_active_threads () const |
| | retrieves the number of active worker threads in the thread pool.
|
| |
| 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 on the global thread pool. More...
|
| |
| 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...
|
| |
| void | wait (size_t millis=0) |
| | waits for all jobs currently running on the thread pool. Has no effect when called from threads other than the one that created the pool. More...
|
| |
|
bool | done () const |
| | checks whether all jobs are done.
|
| |
A work stealing thread pool.
Definition at line 796 of file quickpool.hpp.
◆ ThreadPool()
| quickpool::ThreadPool::ThreadPool |
( |
size_t |
threads = sched::num_cores_avail() | ) |
|
|
inlineexplicit |
constructs a thread pool.
- Parameters
-
| threads | number of worker threads to create; defaults to number of available (virtual) hardware cores. |
Definition at line 802 of file quickpool.hpp.
◆ async()
template<class Function , class... Args>
| auto quickpool::ThreadPool::async |
( |
Function && |
f, |
|
|
Args &&... |
args |
|
) |
| -> std::future<decltype(f(args...))>
|
|
inline |
executes a job asynchronously on the global thread pool.
- Parameters
-
| f | a 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 881 of file quickpool.hpp.
◆ parallel_for()
template<class UnaryFunction >
| void quickpool::ThreadPool::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
-
| begin | first index of the loop. |
| end | the loop runs in the range [begin, end). |
| f | a function taking int argument (the 'loop body'). |
Definition at line 902 of file quickpool.hpp.
◆ parallel_for_each()
template<class Items , class UnaryFunction >
| void quickpool::ThreadPool::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
-
| items | an object allowing for std::begin() and std::end(). |
| f | function to be applied as f(*it) for the iterator in the range [begin, end) (the 'loop body'). |
Definition at line 924 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
-
| f | a function. |
| args | (optional) arguments passed to f. |
Definition at line 867 of file quickpool.hpp.
◆ set_active_threads()
| void quickpool::ThreadPool::set_active_threads |
( |
size_t |
threads | ) |
|
|
inline |
sets the number of active worker threads in the thread pool.
- Parameters
-
| threads | the number of worker threads. Has no effect when not called from owner thread. |
Definition at line 836 of file quickpool.hpp.
◆ wait()
| void quickpool::ThreadPool::wait |
( |
size_t |
millis = 0 | ) |
|
|
inline |
waits for all jobs currently running on the thread pool. Has no effect when called from threads other than the one that created the pool.
- Parameters
-
| millis | if > 0: stops waiting after millis ms. |
Definition at line 935 of file quickpool.hpp.
The documentation for this class was generated from the following file: