Can std :: this_thread :: sleep_for () have false awakenings?

Note that this is not a question about std::condition_variable::wait_for() . I know I can wake up falsely.

My behavior in the program suggests that the answer to this question is Yes, but the STL document is understandable for the condition_variable case. At least on cppreference.com , the correct answer for this_thread looks like No.

The gcc 4.8.1 compiler if this is a defect.

+8
c ++ sleep c ++ 11 stl thread-sleep
source share
1 answer

The relevant sections of the C ++ Standard (paragraphs [thread.thread.this] / 7-9) do not mention anything about side awakenings for std::this_thread::sleep_for , unlike, for example, 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 Sync: None.

9 Throws: timeout exceptions (30.2.4).

This means that the behavior you are observing is inappropriate.

+6
source share

All Articles