GabiMe
GabiMe

Reputation: 18473

gcc bug in condition variable::wait_for

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 ?

Upvotes: 3

Views: 1895

Answers (1)

anthonyvd
anthonyvd

Reputation: 7590

It looks like the standard agrees with you that the clock used should be std::chrono::steady_clock.

§ 30.5.1

  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:

Upvotes: 10

Related Questions