VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
thread_pool.h 文件参考

General-purpose thread pool for parallel task execution. 更多...

#include <functional>
#include <future>
#include <memory>
#include <string>
#include <utility>
#include "./macros.h"
thread_pool.h 的引用(Include)关系图:

浏览该文件的源代码.

 Fixed-size thread pool for parallel task execution. 更多...

命名空间

详细描述

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).

注解
  • 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();