跳转至

ev-stdexec-chrono-steady-clock-003

字段 值
项目 NVIDIA/stdexec
固定 commit 6d7ad689f4d4
路径 include/exec/timed_thread_scheduler.hpp
行段 L175-L185
特性 std::chrono
许可证 Apache-2.0
代码来源 项目源码
级别 manual
审核 zyuhao7 @ 2026-11-03
测试代码 否
发现方式 manual

用法

用 steady_clock::now 驱动定时任务,并用 wait_until 等待下一个截止点

为什么典型

调度器以单调时钟排序定时任务;now 取出当前时刻后弹出所有已到期任务,再把等待截止点交给条件变量的 wait_until,避免忙等。

摘录

        time_point now = std::chrono::steady_clock::now();
        task_type* op  = heap_.front();
        while (op && op->time_point_ <= now)
        {
          heap_.pop_front();
          op->set_value_(op);
          op = heap_.front();
        }
        time_point       deadline = op ? op->time_point_ : now + std::chrono::seconds(2);
        std::unique_lock lock{ready_mutex_};
        cv_.wait_until(lock, deadline, [this] { return ready_ || stop_requested_; });

备注

生产头文件;time_point 比较、now + seconds 运算和 wait_until 组合成事件循环的定时路径,没有轮询。

查看固定 commit 源码 · 返回证据索引