Reputation: 3495
gcc seems to have a problem with sleep_for and sleep_until functions (of namespace std::this_thread). I do some simple example with future and conditional variables. gcc actually uses the System Clock instead of Monotonic Clock and this can cause jumps over time. In my example in some case the clock jumps afterward and my timeout expires immediately.
The Bug should be this GCC Bug 41861
I see that in the future gcc 10 release the bug maybe is resolved, but until the realease of the new version of gcc there is a solution for this problem? Someone have noted that?
UPDATE: This Bug is resolved or not yet in the last compiler version ( GCC 10.2 )?
Upvotes: 2
Views: 811
Reputation: 385108
This is indeed a stunning bug, fixed in GCC 10 (bug 41861 describes it in the context of <condition_variable>
).
Back in the day when I encountered this, it was tempting to fall back on Boost to get the proper behaviour, but even that was broken until 1.61. And nowadays it would be strange to mix Boost and standard timing/threading code anyway, since the standard facilities are generally mature and preferred (irony detected!).
What I did at the time was to create a replacement for condition_variable
that wrapped POSIX functionality directly.
Whatever you're doing with sleep_for
/sleep_until
, I suspect you have little recourse but to do the same thing, sorry.
Upvotes: 5