public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Mike Crowe <mac@mcrowe.com>
Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH 1/2] condition_variable: Report early wakeup of wait_until as no_timeout
Date: Fri, 20 Jul 2018 10:53:00 -0000	[thread overview]
Message-ID: <20180720105338.GQ14057@redhat.com> (raw)
In-Reply-To: <20180710100929.32704-1-mac@mcrowe.com>

On 10/07/18 11:09 +0100, Mike Crowe wrote:
>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[1], 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.

The patch looks good, thanks.

Can we come up with a test for this, using a user-defined clock that
jumps back?


>[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41861
>---
> libstdc++-v3/ChangeLog                      | 5 +++++
> libstdc++-v3/include/std/condition_variable | 8 +++++++-
> 2 files changed, 12 insertions(+), 1 deletion(-)
>
>diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
>index cceef0271ae..ea7875ace9f 100644
>--- a/libstdc++-v3/ChangeLog
>+++ b/libstdc++-v3/ChangeLog
>@@ -1,3 +1,8 @@
>+2018-07-09  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.
>+
> 2018-07-06  François Dumont  <fdumont@gcc.gnu.org>
>
>        * include/debug/functions.h (__gnu_debug::__check_string): Move...
>diff --git a/libstdc++-v3/include/std/condition_variable b/libstdc++-v3/include/std/condition_variable
>index 84863a162d6..a2d146a9b09 100644
>--- a/libstdc++-v3/include/std/condition_variable
>+++ b/libstdc++-v3/include/std/condition_variable
>@@ -116,7 +116,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>        const auto __delta = __atime - __c_entry;
>        const auto __s_atime = __s_entry + __delta;
>
>-       return __wait_until_impl(__lock, __s_atime);
>+       // We might get 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 (__wait_until_impl(__lock, __s_atime) == cv_status::timeout)
>+         return _Clock::now() < __atime ? cv_status::no_timeout : cv_status::timeout;
>+       else
>+         return cv_status::no_timeout;
>       }
>
>     template<typename _Clock, typename _Duration, typename _Predicate>
>--
>2.11.0
>
>BrightSign considers your privacy to be very important. The emails you send to us will be protected and secured. Furthermore, we will only use your email and contact information for the reasons you sent them to us and for tracking how effectively we respond to your requests.

  parent reply	other threads:[~2018-07-20 10:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-10 10:09 Mike Crowe
2018-07-10 10:09 ` [PATCH 2/2] condition_variable: Use steady_clock to implement wait_for Mike Crowe
2018-07-20 10:53 ` Jonathan Wakely [this message]
2018-07-20 11:30   ` [PATCH 1/2] condition_variable: Report early wakeup of wait_until as no_timeout Mike Crowe
2018-07-20 11:44     ` Jonathan Wakely
2018-07-20 16:50 Mike Crowe
2018-08-01 15:41 ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180720105338.GQ14057@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    --cc=mac@mcrowe.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).