https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91906

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Author: redi
Date: Mon Dec  2 16:23:06 2019
New Revision: 278902

URL: https://gcc.gnu.org/viewcvs?rev=278902&root=gcc&view=rev
Log:
libstdc++: Fix timed_mutex::try_lock_until on arbitrary clock (PR 91906)

A non-standard clock may tick more slowly than
std::chrono::steady_clock.  This means that we risk returning false
early when the specified timeout may not have expired. This can be
avoided by looping until the timeout time as reported by the
non-standard clock has been reached.

Unfortunately, we have no way to tell whether the non-standard clock
ticks more quickly that std::chrono::steady_clock. If it does then we
risk returning later than would be expected, but that is unavoidable and
permitted by the standard.

2019-12-02  Mike Crowe  <m...@mcrowe.com>

        PR libstdc++/91906 Fix timed_mutex::try_lock_until on arbitrary clock
        * include/std/mutex (__timed_mutex_impl::_M_try_lock_until): Loop
        until the absolute timeout time is reached as measured against the
        appropriate clock.
        * testsuite/util/slow_clock.h: New file. Move implementation of
        slow_clock test class.
        * testsuite/30_threads/condition_variable/members/2.cc: Include
        slow_clock from header.
        * testsuite/30_threads/shared_timed_mutex/try_lock/3.cc: Convert
        existing test to templated function so that it can be called with
        both system_clock and steady_clock.
        * testsuite/30_threads/timed_mutex/try_lock_until/3.cc: Also run test
        using slow_clock to test above fix.
        * testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc:
        Likewise.
        * testsuite/30_threads/recursive_timed_mutex/try_lock_until/4.cc: Add
        new test that try_lock_until behaves as try_lock if the timeout has
        already expired or exactly matches the current time.

Added:
    trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/4.cc
      - copied, changed from r278901,
trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc
    trunk/libstdc++-v3/testsuite/util/slow_clock.h
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/std/mutex
    trunk/libstdc++-v3/testsuite/30_threads/condition_variable/members/2.cc
   
trunk/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc
    trunk/libstdc++-v3/testsuite/30_threads/shared_timed_mutex/try_lock/3.cc
    trunk/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc

Reply via email to