#include <thread_pool.hpp>
|
typedef std::function< void()> | task_t |
|
◆ task_t
task typedef simply a callable taking no parameter
◆ thread_pool() [1/2]
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 |
◆ ~thread_pool()
tacopie::utils::thread_pool::~thread_pool |
( |
void |
| ) |
|
◆ thread_pool() [2/2]
tacopie::utils::thread_pool::thread_pool |
( |
const thread_pool & |
| ) |
|
|
delete |
◆ 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 |
◆ fetch_task()
task_t tacopie::utils::thread_pool::fetch_task |
( |
void |
| ) |
|
|
private |
retrieve a new task fetch the first element in the queue, or wait if no task are available may return null if the threadpool is stopped
◆ 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
◆ operator=()
◆ run()
void tacopie::utils::thread_pool::run |
( |
void |
| ) |
|
|
private |
◆ 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 |
◆ should_stop()
bool tacopie::utils::thread_pool::should_stop |
( |
void |
| ) |
const |
|
private |
- Returns
- whether the thread should stop or not
◆ 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
◆ m_nb_threads
std::size_t tacopie::utils::thread_pool::m_nb_threads |
|
private |
number of threads allowed
◆ m_should_stop
std::atomic<bool> tacopie::utils::thread_pool::m_should_stop = ATOMIC_VAR_INIT(false) |
|
private |
◆ m_tasks
std::queue<task_t> tacopie::utils::thread_pool::m_tasks |
|
private |
◆ m_tasks_condvar
std::condition_variable tacopie::utils::thread_pool::m_tasks_condvar |
|
private |
task condvar to sync on tasks changes
◆ m_tasks_mtx
std::mutex tacopie::utils::thread_pool::m_tasks_mtx |
|
private |
◆ m_workers
std::vector<std::thread> tacopie::utils::thread_pool::m_workers |
|
private |
The documentation for this class was generated from the following file: