#include <thread_pool.hpp>
|
typedef std::function< void()> | task_t |
|
basic thread pool used to push async tasks from the io_service
◆ task_t
task typedef simply a callable taking no parameter
◆ thread_pool()
tacopie::utils::thread_pool::thread_pool |
( |
std::size_t |
nb_threads | ) |
|
|
explicit |
ctor created the worker thread that start working immediately
- Parameters
-
nb_threads | number of threads to start the thread pool |
◆ add_task()
void tacopie::utils::thread_pool::add_task |
( |
const task_t & |
task | ) |
|
add tasks to thread pool task is enqueued and will be executed whenever all previously executed tasked have been executed (or are currently being executed)
- Parameters
-
task | task to be executed by the threadpool |
◆ is_running()
bool tacopie::utils::thread_pool::is_running |
( |
void |
| ) |
const |
◆ operator<<()
same as add_task
- Parameters
-
task | task to be executed by the threadpool |
- Returns
- current instance
◆ set_nb_threads()
void tacopie::utils::thread_pool::set_nb_threads |
( |
std::size_t |
nb_threads | ) |
|
reset the number of threads working in the thread pool this can be safely called at runtime and can be useful if you need to adjust the number of workers
this function returns immediately, but change might be applied in the background that is, increasing number of threads will spwan new threads directly from this function (but they may take a while to start) moreover, shrinking the number of threads can only be applied in the background to make sure to not stop some threads in the middle of their task
changing number of workers do not affect tasks to be executed and tasks currently being executed
- Parameters
-
nb_threads | number of threads |
◆ stop()
void tacopie::utils::thread_pool::stop |
( |
void |
| ) |
|
stop the thread pool and wait for workers completion if some tasks are pending, they won't be executed
The documentation for this class was generated from the following file: