|
VLink
2.0.0
A high-performance communication middleware
|
Fixed-size worker pool for parallel task execution. More...
#include <functional>#include <future>#include <memory>#include <string>#include <tuple>#include <type_traits>#include <utility>#include "./functional.h"#include "./macros.h"#include "./memory_resource.h"#include "./task_handle.h"Go to the source code of this file.
Classes | |
| class | vlink::ThreadPool |
| Fixed worker pool that consumes a shared task queue. More... | |
Namespaces | |
| vlink | |
Fixed-size worker pool for parallel task execution.
vlink::ThreadPool launches a configurable number of worker threads at construction and dispatches submitted tasks to whichever worker is idle. Unlike MessageLoop, the pool has no built-in timer mechanism or loop lifecycle; it is started immediately and torn down with shutdown(). A pool created with zero workers is left in the shutdown state and rejects every submission.
Architecture:
* post_task() -----> +---------------------------+ * | shared dispatcher queue | * +-----+----------+----------+ * | | | * v v v * worker 1 worker 2 ... worker N * | | | * v v v * user task user task user task *
Queue implementations:
| Type | Backing queue | Notes |
|---|---|---|
kNormalType | Mutex-protected std::deque (or std::pmr) | Default; honours drop policy |
kLockfreeType | MpmcQueue (lock-free multi-producer/consumer) | Lower contention overhead |
Push-side back-pressure strategies are identical to MessageLoop::Strategy. They only affect submission when the queue is full; worker wake-up is always driven by a condition variable.
invoke_task() returns a std::future; blocking on it from a pool worker can deadlock if every worker is busy.is_in_work_thread() can detect re-entrant submissions.