Flow
Documentation for the Flow C++ Library
|
A simple thread pool with fixed number of worker threads. All the threads poll tasks from a single queue. If all the threads are waiting, then the user must manually call runPendingTask() to resolve deadlock. More...
#include <flow_simple_thread_pool.h>
Public Member Functions | |
SimpleThreadPool (std::size_t threadCount=std::thread::hardware_concurrency() - 1) | |
std::size_t | poolSize () const |
template<typename Callable, typename ... Args> | |
std::future< std::invoke_result_t< Callable, Args &&... > > | submit (Callable callable, Args &&... args) |
Submit a task to the thread pool queue. | |
void | runPendingTask () |
Try run a task from the pool queue. If the queue is empty, then it yields the thread. This helps resolves thread deadlock due to dependency waiting. |
Private Member Functions | |
void | runTasks (std::stop_token token) |
Private Attributes | |
flow::Vector< std::jthread > | threads_ |
ThreadSafeQueue | queue_ |
A simple thread pool with fixed number of worker threads. All the threads poll tasks from a single queue. If all the threads are waiting, then the user must manually call runPendingTask() to resolve deadlock.
Definition at line 15 of file flow_simple_thread_pool.h.
|
inlineexplicit |
Definition at line 20 of file flow_simple_thread_pool.h.
References runTasks(), and threads_.
|
inline |
Definition at line 28 of file flow_simple_thread_pool.h.
References threads_.
|
inline |
Try run a task from the pool queue. If the queue is empty, then it yields the thread. This helps resolves thread deadlock due to dependency waiting.
Definition at line 47 of file flow_simple_thread_pool.h.
References queue_.
Referenced by runTasks().
|
inlineprivate |
Definition at line 56 of file flow_simple_thread_pool.h.
References runPendingTask().
Referenced by SimpleThreadPool().
|
inline |
Submit a task to the thread pool queue.
callable | The callable. |
...args | The callable arguments. |
Definition at line 36 of file flow_simple_thread_pool.h.
References queue_.
|
private |
Definition at line 17 of file flow_simple_thread_pool.h.
Referenced by runPendingTask(), and submit().
|
private |
Definition at line 16 of file flow_simple_thread_pool.h.
Referenced by poolSize(), and SimpleThreadPool().