|
Flow
Documentation for the Flow C++ Library
|
A work-stealing multiqueue threadpool. Each worker thread has a thread_local task queue to reduce thread contention. More...
#include <flow_multi_queue_thread_pool.h>
Public Member Functions | |
| MultiQueueThreadPool (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-local queue. If the task is submit by an external thread outside of the thread pool, then it submits to the pool queue shared by all threads instead. | |
| void | runPendingTask () |
| Try run a task from the local queue. If the local queue is empty, it tries to run a task from the pool queue. If the pool queue is empty, it tries to steal the work from other thread's local queue. If all queues are empty, then it yields the thread. This helps resolves thread deadlock due to dependency waiting. | |
Private Member Functions | |
| void | runTasks (std::stop_token token, std::size_t id) |
Private Attributes | |
| flow::Vector< std::jthread > | threads_ |
| flow::Vector< LocalQueue > | localQueues_ |
| ThreadSafeQueue | poolQueue_ |
Static Private Attributes | |
| static thread_local std::size_t | threadId = 0 |
| static thread_local LocalQueue * | localQueue = nullptr |
A work-stealing multiqueue threadpool. Each worker thread has a thread_local task queue to reduce thread contention.
Definition at line 15 of file flow_multi_queue_thread_pool.h.
|
inlineexplicit |
Definition at line 24 of file flow_multi_queue_thread_pool.h.
References localQueues_, runTasks(), and threads_.
|
inline |
Definition at line 34 of file flow_multi_queue_thread_pool.h.
References threads_.
Referenced by runPendingTask().
|
inline |
Try run a task from the local queue. If the local queue is empty, it tries to run a task from the pool queue. If the pool queue is empty, it tries to steal the work from other thread's local queue. If all queues are empty, then it yields the thread. This helps resolves thread deadlock due to dependency waiting.
Definition at line 63 of file flow_multi_queue_thread_pool.h.
References localQueue, localQueues_, poolQueue_, poolSize(), and threadId.
Referenced by runTasks().
|
inlineprivate |
Definition at line 93 of file flow_multi_queue_thread_pool.h.
References localQueue, localQueues_, runPendingTask(), and threadId.
Referenced by MultiQueueThreadPool().
|
inline |
Submit a task to the thread-local queue. If the task is submit by an external thread outside of the thread pool, then it submits to the pool queue shared by all threads instead.
| callable | The callable. |
| ...args | The callable arguments. |
Definition at line 44 of file flow_multi_queue_thread_pool.h.
References localQueue, and poolQueue_.
|
inlinestaticprivate |
Definition at line 21 of file flow_multi_queue_thread_pool.h.
Referenced by runPendingTask(), runTasks(), and submit().
|
private |
Definition at line 17 of file flow_multi_queue_thread_pool.h.
Referenced by MultiQueueThreadPool(), runPendingTask(), and runTasks().
|
private |
Definition at line 18 of file flow_multi_queue_thread_pool.h.
Referenced by runPendingTask(), and submit().
|
inlinestaticprivate |
Definition at line 20 of file flow_multi_queue_thread_pool.h.
Referenced by runPendingTask(), and runTasks().
|
private |
Definition at line 16 of file flow_multi_queue_thread_pool.h.
Referenced by MultiQueueThreadPool(), and poolSize().