gpt4 book ai didi

c++ - std::this_thread::sleep_for() 可以有虚假唤醒吗?

转载 作者:可可西里 更新时间:2023-11-01 17:39:05 25 4
gpt4 key购买 nike

请注意,这不是关于 std::condition_variable::wait_for() 的问题。我知道这可能会虚假唤醒。

我的程序的行为表明这个问题的答案是肯定的,但是 STL 文档对于 condition_variable 的情况非常清楚。至少在 cppreference.com , this_thread 的正确答案似乎是否。

编译器是 gcc 4.8.1,以防这是一个缺陷。

最佳答案

C++ 标准的相关部分(第 [thread.thread.this]/7-9 段)没有提及任何关于 std::this_thread::sleep_for 的虚假唤醒,不像例如对于 std::condition_variable::wait_for

template <class Rep, class Period>
void sleep_for(const chrono::duration<Rep, Period>& rel_time);

7 Effects: Blocks the calling thread for the relative timeout (30.2.4) specified by rel_time.

8 Synchronization: None.

9 Throws: Timeout-related exceptions (30.2.4).

这意味着您观察到的行为是不合格的。

关于c++ - std::this_thread::sleep_for() 可以有虚假唤醒吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30538508/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com