简体   繁体   English

std :: this_thread :: sleep_for()有没有虚假的唤醒?

[英]Can std::this_thread::sleep_for() have spurious wakeups?

Note, this is not a question about std::condition_variable::wait_for() . 注意,这不是关于std::condition_variable::wait_for() I know that can wake spuriously. 我知道可以假装醒来。

My program's behavior suggests the answer to this question is Yes, but the STL documentation is quite clear for the condition_variable case. 我的程序的行为表明这个问题的答案是肯定的,但是对于condition_variable案例,STL文档非常清楚。 At least at cppreference.com , the correct answer for this_thread appears to be No. 至少在cppreference.com上 ,this_thread的正确答案似乎是否定的。

Compiler is gcc 4.8.1, in case this is a defect. 编译器是gcc 4.8.1,如果这是一个缺陷。

The relevant sections of the C++ Standard (paragraphs [thread.thread.this]/7-9) do not mention anything about spurious wake-ups for std::this_thread::sleep_for , unlike eg for std::condition_variable::wait_for . 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 . 7种效果 :块用于通过指定的相对超时(30.2.4)调用线程rel_time

8 Synchronization : None. 8 同步 :无。

9 Throws : Timeout-related exceptions (30.2.4). 9 抛出 :超时相关的例外(30.2.4)。

This implies that the behavior you are observing is non-conforming. 这意味着您观察到的行为是不符合的。

Able to reproduce on GCC 4.8.5. 能够在GCC 4.8.5上重现。

There is also a bug reported (and confirmed) against GCC 5.1.0 ( gcc.gnu.org/bugzilla/show_bug.cgi?id=66803 ) 还有针对GCC 5.1.0报告(并确认)的错误( gcc.gnu.org/bugzilla/show_bug.cgi?id=66803

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM