Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当您在延迟任务对象上调用 std::future::wait_for 时会发生什么?
理想情况下,我想唤醒一个延迟任务,但不想在当前线程中处理任务。
在第一次调用非定时等待函数(像 一样阻塞的函数)之前async,对策略的调用不会执行延迟任务。这在语言规范 [futures.async] 部分第 3.2 段中有详细说明:launch::deferredget
async
launch::deferred
get
在引用此共享状态的异步返回对象上第一次调用非定时等待函数(33.6.5)应调用调用等待函数的线程中的延迟函数。
所以这将在当前线程中运行任务。我想您可以创建另一个线程,并将任务传递给它以运行。