This is the mail archive of the
mailing list for the libstdc++ project.
Re: [PATCH 0/5] Make std::future::wait_* use std::chrono::steady_clock when required
- From: Torvald Riegel <triegel at redhat dot com>
- To: Mike Crowe <mac at mcrowe dot com>
- Cc: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org, Jonathan Wakely <jwakely at redhat dot com>
- Date: Sat, 13 Jan 2018 16:29:57 +0100
- Subject: Re: [PATCH 0/5] Make std::future::wait_* use std::chrono::steady_clock when required
- Authentication-results: sourceware.org; auth=none
- References: <email@example.com>
On Sun, 2018-01-07 at 20:55 +0000, Mike Crowe wrote:
> This patch series was originally submitted back in September at
> https://gcc.gnu.org/ml/libstdc++/2017-09/msg00083.html which ended up
> as https://patchwork.ozlabs.org/cover/817379/ . The patches received
> no comments at all, which may mean that they are perfect or that they
> are so bad that no-one knew where to start with criticising them. It
> would be good to know which. :)
> The patches are unchanged from last time, but I have corrected a typo
> in one of the commit messages. The original cover message follows.
> This is a first attempt to make std::future::wait_until and
> std::future::wait_for make correct use of
> std::chrono::steady_clock/CLOCK_MONOTONIC. It also makes
> std::future::wait_until react to changes to CLOCK_REALTIME during the
> wait, but only when passed a std::chrono::system_clock time point.
I have comments on the design.
First, I don't think we should not change
__atomic_futex_unsigned_base::_M_futex_wait_until, as there's a risk
that we'll change behavior of existing applications that work as
Instead, ISTM we should additionally expose the two options we have at
the level of futexes:
* Relative timeout using CLOCK_MONOTONIC
* Absolute timeout using CLOCK_REALTIME (which will fall back to the
former on old kernels, which is fine I think).
Then we do the following translations from functions that programs would
call to the new futex functions:
1) wait_for is a loop in which we load the current time from the steady
clock, then call the relative futex wait, and if that returns for a
spurious reason (ie, neither timeout nor is the expected value present),
we reduce the prior relative amount by the difference between the time
before the futex wait and the current time.
2) wait_until using the steady clock is a loop similar to wait_for, just
that we additionally compute the initial relative timeout.
3) wait_until using the system clock is a loop that uses
absolute-timeout futex wait.
4) For wait_until using an unknown clock, I'd say that synching to the
system clock is the right approach. Using wait_until indicates that the
programmer wanted to have a point in time, not a duration.
Does this work for you?
If so, could you provide a revised patch that uses this approach and
includes this approach in the documentation?
(Sorry for the lack of comments in the current code).