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]

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

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.

 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 ea7875ace9f..4500273ace7 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,4 +1,7 @@
 2018-07-09  Mike Crowe <>
+       * include/std/condition_variable (wait_for): Use steady_clock.
+2018-07-09  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 a2d146a9b09..ce583990b9d 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>

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]