|
World Ocean Simulation System (WOSS) library
|
#include <thread-pool-definitions.h>

Public Types | |
| using | Task = std::function< void() > |
Public Member Functions | |
| ThreadPool (size_t n_threads) | |
| ~ThreadPool () | |
| template<class F , class... Args> | |
| auto | submit (F &&f, Args &&... args) -> std::future< decltype(std::forward< F >(f)(std::forward< Args >(args)...))> |
| Submits a task to the thread pool. | |
| size_t | getNumThreads () |
| Gets the number of threads in the pool. | |
Private Member Functions | |
| void | start () |
| void | stop () |
Private Attributes | |
| size_t | num_threads |
| std::vector< std::thread > | workers |
| std::queue< Task > | tasks |
| std::mutex | queue_mutex |
| std::condition_variable | task_cond_var |
| bool | stop_flag |
ThreadPool class manages a fixed number of worker threads that pick up and execute tasks from a shared queue.
| using woss::ThreadPool::Task = std::function< void() > |
Task type: A generic callable that takes no arguments and returns nothing.
|
inlineexplicit |
Constructor, Initializes the thread pool with a specified number of threads.
| n_threads | number of threads. If set to 0, then system will automatically pick the max allowed number of threads. |
References num_threads, and start().

|
inline |
Destructor, Ensures all worker threads are joined and the pool is properly shut down.
References stop().

|
inline |
Gets the number of threads in the pool.
References num_threads.
|
inlineprivate |
Creates up to num_threads std::thread and make them wait for work
References num_threads, queue_mutex, stop_flag, task_cond_var, tasks, and workers.
Referenced by ThreadPool().
|
inlineprivate |
Sets the stop_flag, wakes up every thread and wait for them to exit.
References queue_mutex, stop_flag, task_cond_var, and workers.
Referenced by ~ThreadPool().
|
inline |
Submits a task to the thread pool.
| f | is the function type (e.g., a lambda, a regular function pointer, std::function). |
| args | are the types of the arguments for the function F. |
References queue_mutex, stop_flag, task_cond_var, and tasks.
Referenced by woss::WossManagerResDbMT::getWossPressure(), woss::WossManagerResDbMT::getWossPressure(), woss::WossManagerResDbMT::getWossTimeArr(), and woss::WossManagerResDbMT::getWossTimeArr().
|
private |
The number of threads in the pool.
Referenced by getNumThreads(), start(), and ThreadPool().
|
private |
|
private |
|
private |
|
private |
|
private |