Seems there is a bug in gcc's std::condition_variable::cv.wait_for()
.
If the system time change during the wait, it will return after the wrong period.
Most often - it just doesn't return if the time is moved to the past, or awakes immediately if time moves to the future.
I think the cause is that it uses system clock instead if steady_clock ( https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/std/condition_variable#L67 ).
Did anybody come across this issue ? what could be a workaround ?
It looks like the standard agrees with you that the clock used should be std::chrono::steady_clock
.
§ 30.5.1
- Effects: as if
return wait_until(lock, chrono::steady_clock::now() + rel_time, std::move(pred));
This bug also appears to be tracked by the GCC folks already.
As for fixes/workarounds you could:
libstdc++
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.