This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 2/2] condition_variable: Use steady_clock to implement wait_for

On 20/07/18 17:49 +0100, Mike Crowe wrote:
I believe[1][2] that the C++ standard says that
std::condition_variable::wait_for should be implemented to be equivalent

return wait_until(lock, chrono::steady_clock::now() + rel_time);

But the existing implementation uses chrono::system_clock. Now that
wait_until has potentially-different behaviour for chrono::steady_clock,
let's at least try to wait using the correct clock.


Also committed to trunk. Thanks again.

libstdc++-v3/ChangeLog                      | 3 +++
libstdc++-v3/include/std/condition_variable | 5 +++--
2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 4657af7..432cb84 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,4 +1,7 @@
2018-07-20  Mike Crowe <>
+       * include/std/condition_variable (wait_for): Use steady_clock.
+2018-07-20  Mike Crowe <>
       * include/std/condition_variable (wait_until): Only report timeout
       if we really have timed out when measured against the
       caller-supplied clock.
diff --git a/libstdc++-v3/include/std/condition_variable b/libstdc++-v3/include/std/condition_variable
index a2d146a..ce58399 100644
--- a/libstdc++-v3/include/std/condition_variable
+++ b/libstdc++-v3/include/std/condition_variable
  class condition_variable
    typedef chrono::system_clock       __clock_t;
+    typedef chrono::steady_clock       __steady_clock_t;
    typedef __gthread_cond_t           __native_type;

      wait_for(unique_lock<mutex>& __lock,
              const chrono::duration<_Rep, _Period>& __rtime)
-       using __dur = typename __clock_t::duration;
+       using __dur = typename __steady_clock_t::duration;
       auto __reltime = chrono::duration_cast<__dur>(__rtime);
       if (__reltime < __rtime)
-       return wait_until(__lock, __clock_t::now() + __reltime);
+       return wait_until(__lock, __steady_clock_t::now() + __reltime);

    template<typename _Rep, typename _Period, typename _Predicate>
git-series 0.9.1
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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]