VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
thread_pool.h File Reference

General-purpose thread pool for parallel task execution. More...

#include <functional>
#include <future>
#include <memory>
#include <string>
#include <utility>
#include "./macros.h"
Include dependency graph for thread_pool.h:

Go to the source code of this file.

Classes

 Fixed-size thread pool for parallel task execution. More...

Namespaces

Detailed Description

General-purpose thread pool for parallel task execution.

ThreadPool maintains a fixed number of worker threads that dequeue and execute tasks posted via post_task() or invoke_task(). Unlike MessageLoop, there is no timer support or loop lifecycle; the pool is started on construction and shut down with shutdown().

Queue types:

Type Queue implementation Notes
kNormalType Mutex-protected std::queue Default
kLockfreeType MpmcQueue (lock-free MPMC) Lower overhead under contention

Idle strategies (same semantics as MessageLoop::Strategy).

Note
  • Tasks may execute concurrently; shared state must be protected externally.
  • invoke_task() returns a std::future. Blocking on the future from a thread pool worker will deadlock if all workers are busy.
  • is_in_work_thread() can be used to detect reentrant calls.
Example
pool.post_task([] { heavy_work(); });
auto fut = pool.invoke_task([]() -> int { return compute(); });
int result = fut.get();
pool.shutdown();