|
bitsim
Model, simulate, estimate and control robots in C++
|
A fixed number of threads that run the tasks given to them, in the order given. More...
#include <thread_pool.h>


Public Member Functions | |
| ThreadPool (uint_t n_threads=0) | |
| Start n_threads threads; 0 means default_n_threads(). | |
| ~ThreadPool () | |
| Run the tasks still queued, then join the threads. | |
| uint_t | size () const noexcept |
| The number of threads. | |
| bool | is_worker_thread () const noexcept |
| Whether the calling thread is one of this pool's threads. | |
| template<typename F, typename... Args> | |
| auto | submit (F &&f, Args &&...args) -> std::future< std::invoke_result_t< F, Args... > > |
| Queue f(args...) to run on one of the threads. | |
Static Public Member Functions | |
| static uint_t | default_n_threads () |
| The number of threads to use when none is given: the environment variable BITSIM_NUM_THREADS if it is a positive number, otherwise the number of cores. | |
A fixed number of threads that run the tasks given to them, in the order given.
submit() returns a std::future for the task's result; an exception the task throws comes out of the future's get(). The destructor runs the tasks still queued, then joins the threads.
Most code needs only parallel_for() and parallel_map() in bitsim/utils/concurrency/parallel.h, which use default_thread_pool().
|
explicit |
Start n_threads threads; 0 means default_n_threads().
| bitsim::utils::concurrency::ThreadPool::~ThreadPool | ( | ) |
Run the tasks still queued, then join the threads.
|
static |
The number of threads to use when none is given: the environment variable BITSIM_NUM_THREADS if it is a positive number, otherwise the number of cores.
|
noexcept |
Whether the calling thread is one of this pool's threads.
A task that waits for other tasks of its own pool can leave no thread to run them; parallel_for() checks this and runs serially inside a task.
|
inlinenoexcept |
The number of threads.
| auto bitsim::utils::concurrency::ThreadPool::submit | ( | F && | f, |
| Args &&... | args )->std::future< std::invoke_result_t< F, Args... > > |
Queue f(args...) to run on one of the threads.