Bug 93542 - std::future::wait_for should use monotonic clock
Summary: std::future::wait_for should use monotonic clock
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 9.2.1
: P3 normal
Target Milestone: 11.0
Assignee: Mike Crowe
Keywords: patch
Depends on:
Reported: 2020-02-02 17:41 UTC by Mike Crowe
Modified: 2020-10-05 09:47 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2020-02-02 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description Mike Crowe 2020-02-02 17:41:47 UTC
std::future::wait_for calls __atomic_futex_unsigned._M_load_when_equal_for which calculates an absolute time measured against std::chrono::system_clock. This results in the timeout changing if the system clock is warped.

std::future::wait_for should behave the same as std::condition_variable::wait_for and wait against std::chrono::steady_clock.

Similarly, calling std::future::wait_until with a std::chrono::steady_clock parameter results in a wait against std::chrono::system_clock.

(A fix for this is available in https://gcc.gnu.org/ml/gcc-patches/2019-10/msg01932.html .)
Comment 1 Jonathan Wakely 2020-02-02 20:35:25 UTC
Confirmed, thanks Mike.
Comment 2 Mike Crowe 2020-06-05 11:57:03 UTC
An updated version of the fix is available in https://gcc.gnu.org/pipermail/libstdc++/2020-May/050433.html which relies on https://gcc.gnu.org/pipermail/libstdc++/2020-May/050439.html .
Comment 3 Mike Crowe 2020-10-03 16:27:30 UTC
The patches mentioned in comment 2 landed for GCC 11 as 87fce1923fcc8d6ef508500475c149082dc9d338 and 01d412ef36f56c6961858f4d3d395d000e3f1c06 respectively. It seems that I failed to include the bug number in the commit message. :(
Comment 4 Jonathan Wakely 2020-10-05 09:47:35 UTC
Thanks, Mike. I've added the PR number to the ChangeLog file in g:b98d3cc5666f36bf3cbeed7cd6a23483cc5e4eca