diff options
author | Mike Crowe <mac@mcrowe.com> | 2018-08-01 15:39:45 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2018-08-01 16:39:45 +0100 |
commit | 2f5934326542b3f303db91cc4cd432cd488f0258 (patch) | |
tree | 1d909cf9f46064af55af5dae9bb10e0263463b8c /libstdc++-v3/include/std/condition_variable | |
parent | 5534096c09d8d8bc4e12b73d1db179ccd7c60671 (diff) | |
download | gcc-2f5934326542b3f303db91cc4cd432cd488f0258.zip gcc-2f5934326542b3f303db91cc4cd432cd488f0258.tar.gz gcc-2f5934326542b3f303db91cc4cd432cd488f0258.tar.bz2 |
Report early wakeup of condition_variable::wait_until as no_timeout
As currently implemented, condition_variable always ultimately waits
against std::chrono::system_clock. This clock can be changed in arbitrary
ways by the user which may result in us waking up too early or too late
when measured against the caller-supplied clock.
We can't (yet) do much about waking up too late (PR 41861), but
if we wake up too early we must return cv_status::no_timeout to indicate a
spurious wakeup rather than incorrectly returning cv_status::timeout.
2018-08-01 Mike Crowe <mac@mcrowe.com>
* include/std/condition_variable (wait_until): Only report timeout
if we really have timed out when measured against the
caller-supplied clock.
* testsuite/30_threads/condition_variable/members/2.cc: Add test
case to confirm above behaviour.
From-SVN: r263224
Diffstat (limited to 'libstdc++-v3/include/std/condition_variable')
-rw-r--r-- | libstdc++-v3/include/std/condition_variable | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/libstdc++-v3/include/std/condition_variable b/libstdc++-v3/include/std/condition_variable index 3f690c8..c00afa2 100644 --- a/libstdc++-v3/include/std/condition_variable +++ b/libstdc++-v3/include/std/condition_variable @@ -117,7 +117,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const auto __delta = __atime - __c_entry; const auto __s_atime = __s_entry + __delta; - return __wait_until_impl(__lock, __s_atime); + if (__wait_until_impl(__lock, __s_atime) == cv_status::no_timeout) + return cv_status::no_timeout; + // We got a timeout when measured against __clock_t but + // we need to check against the caller-supplied clock + // to tell whether we should return a timeout. + if (_Clock::now() < __atime) + return cv_status::no_timeout; + return cv_status::timeout; } template<typename _Clock, typename _Duration, typename _Predicate> |