multithreading - 在指定时间唤醒线程

标签 multithreading c++11

我想在指定时间唤醒线程。我可以这样吗?

#include <chrono>
#include <thread>
using namespace std::literals::chrono_literals;
void foo() {}
int main()
{
    using clock = std::chrono::steady_clock;
    clock::time_point next_time_point = clock::now() + 20s;
    foo();
    std::this_thread::sleep_until(next_time_point);
}

最佳答案

您永远不应该使用 sleep 。而是等待条件变量

关于multithreading - 在指定时间唤醒线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37985443/

相关文章:

c# - 忙等待线程

c++ - 已知参数的模板推导失败

c++ - 为什么enable_shared_from_this必须公开继承?

web-services - 从线程调用远程 SOAP 调用时发生异常

java - Selenium Webdriver TestNG 测试彼此都是 "overwriting"

Java - 多线程和文件问题

c++ - 我是否必须手动实现比较运算符的交换性?

c++ - 将 std::make_unique 与自定义删除器一起使用

c++ - move_iterator 是做什么用的

multithreading - Appium并行执行+ TestNG框架问题