C++26未引入Executor标准类型,而是以sender/receiver契约、schedule/then等组合原语替代;并发改进聚焦std::jthread自动停止与stop_token泛化。

Executors 提案(P0443R14 及后续修订)**不会落地为标准库的一部分**——它已被拆解、重构,并以更小粒度的组件形式分散进入 C++26,核心目标不是“统一异步模型”,而是**提供可组合、可定制的执行抽象基元,供更高层库(如 std::async、std::jthread、协程库)底层复用**。
Executors 没有直接暴露 executor 类型给用户
你不会在 C++26 标准头文件里看到 std::executor 或 std::thread_pool_executor。提案最终放弃“一刀切”的 executor 接口设计,转而聚焦于:
-
std::execution::sender和std::execution::receiver:定义异步操作的生产者/消费者契约(用于std::async和协程 awaiter 互操作) -
std::execution::schedule():最简调度原语,返回一个sender,表示“在某个隐式执行上下文中就绪” -
std::execution::then()、std::execution::upon_error()等适配器:用于组合 sender 链,但不强制绑定到具体线程或队列
co_await 或 std::async,只是它们底层可能共享同一套 sender/receiver 调度语义,而非各自实现一套线程分发逻辑。
C++26 中真正可用的并发新特性是 std::jthread 增强与 std::stop_token 泛化
相比遥不可及的 executor 模型,C++26 更实在的并发改进集中在协作式取消和线程生命周期管理:
-
std::jthread现在支持构造时传入std::stop_token,且其析构自动调用request_stop()—— 不再需要手动join()或detach() -
std::stop_source和std::stop_token可跨std::thread、std::jthread、甚至协程作用域传递,取消信号真正可穿透异步栈 -
std::this_thread::get_stop_token()成为标准函数,协程中可直接获取当前线程的停止句柄
#include#include #include void worker(std::stop_token stoken) { while (!stoken.stop_requested()) { // 工作中... std::this_thread::sleep_for(10ms); } } int main() { std::jthread t{worker}; // 自动绑定 stop_source,析构时 request_stop() // 不需要显式 t.request_stop() 或 t.join() }
第三方库(如 libunifex、cppcoro)已比标准更早实践了 executor 思想
如果你真想用类 executor 的调度模型,现在就得依赖外部库:
-
libunifex提供inline_scheduler、thread_pool、single_thread_context等具体调度器,API 接近 P0443 原始设计 - 它的
submit()、schedule()、let_value()等操作符可直接组合,且与 C++23 协程兼容 - 但注意:这些类型与标准
std::execution::sender并不 ABI 兼容,C++26 的 sender 是简化版,两者不能混用
std::stop_token,那 executor 提案对你当前项目基本没影响。










