public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 00/11] timed_mutex, shared_timed_mutex: Add full steady clock support
@ 2019-09-28  8:45 Mike Crowe
  2019-09-28  8:45 ` [PATCH 05/11] PR libstdc++/78237 Add full steady_clock support to timed_mutex Mike Crowe
                   ` (10 more replies)
  0 siblings, 11 replies; 14+ messages in thread
From: Mike Crowe @ 2019-09-28  8:45 UTC (permalink / raw)
  To: libstdc++, gcc-patches; +Cc: Mike Crowe

glibc v2.30 added the pthread_mutex_clocklock,
pthread_rwlock_clockrdlock and pthread_rwlock_clockwrlock
functions. These accept CLOCK_MONOTONIC, so they can be used to
implement proper steady_clock support in timed_mutex,
recursive_timed_mutex and shared_timed_mutex that is immune to the
system clock being warped.

Unfortunately we can't warp the system clock in the testsuite, so it's
not possible to automatically ensure that the system_clock test cases
result in a wait on CLOCK_REALTIME and steady_clock test cases result
in a wait on CLOCK_MONOTONIC. It's recommended to run the test under
strace(1) and check whether the expected futex calls are made by glibc
or ltrace(1) and check whether the expected pthread calls are
made. The easiest way to do this is to copy and paste the line used to
build the test from the output of running the tests (for example):

 make check-target-libstdc++-v3 RUNTESTFLAGS="conformance.exp=30_threads/shared_mutex/* -v -v"

to compile the test with only the tests for one clock enabled and then
run it as:

 strace -f ./1.exe

You should see calls to:

 futex(..., FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, ...)

with large values of tv_sec when using system_clock and calls to:

 futex(..., FUTEX_WAIT_BITSET_PRIVATE, ...)

Alternatively, you can use:

 ltrace -f ./1.exe

and look for calls to pthread_mutex_clocklock,
pthread_rwlock_clockrdlock and pthread_rwlock_clockwrlock with a
parameter of 1 for CLOCK_MONOTONIC and with values of tv_sec based on
the system uptime when using steady_clock.

This series also adds some extra tests and fixes some other minor
problems with the existing implementation and tests.

Mike Crowe (11):
  libstdc++ testsuite: Check return value from timed_mutex::try_lock_until
  libstdc++ testsuite: Add timed_mutex::try_lock_until test
  libstdc++ testsuite: Also test timed_mutex with steady_clock
  libstdc++ testsuite: Also test unique_lock::try_lock_until with steady_clock
  PR libstdc++/78237 Add full steady_clock support to timed_mutex
  libstdc++ testsuite: Move slow_clock to its own header
  PR libstdc++/91906 Fix timed_mutex::try_lock_until on arbitrary clock
  libstdc++ testsuite: Also test shared_timed_mutex with steady_clock
  libstdc++ shared_mutex: Add full steady_clock support to shared_timed_mutex
  libstdc++ timed_mutex: Ensure that try_lock_for waits for long enough
  shared_mutex: Fix try_lock_until and try_lock_shared_until on arbitrary clock

 libstdc++-v3/acinclude.m4                                                   |  64 +++++++++++++++++++++++++++-
 libstdc++-v3/config.h.in                                                    |   7 +++-
 libstdc++-v3/configure                                                      | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 libstdc++-v3/configure.ac                                                   |   6 +++-
 libstdc++-v3/include/std/mutex                                              |  60 +++++++++++++++++++++----
 libstdc++-v3/include/std/shared_mutex                                       | 117 +++++++++++++++++++++++++++++++++++++++++---------
 libstdc++-v3/testsuite/30_threads/condition_variable/members/2.cc           |  17 +-------
 libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc |  76 ++++++++++++++++++++++++++++++++-
 libstdc++-v3/testsuite/30_threads/shared_mutex/try_lock_until/1.cc          |  87 +++++++++++++++++++++++++++++++++++++-
 libstdc++-v3/testsuite/30_threads/shared_timed_mutex/try_lock/3.cc          |  17 ++++---
 libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc           |  76 ++++++++++++++++++++++++++++++++-
 libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/57641.cc       |  18 +++++---
 libstdc++-v3/testsuite/30_threads/unique_lock/locking/4.cc                  |  14 ++++--
 libstdc++-v3/testsuite/util/slow_clock.h                                    |  38 ++++++++++++++++-
 14 files changed, 707 insertions(+), 60 deletions(-)
 create mode 100644 libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/shared_mutex/try_lock_until/1.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc
 create mode 100644 libstdc++-v3/testsuite/util/slow_clock.h

base-commit: dcfd68ec29a6823f75a52c934fe408ce4b4b6919
-- 
git-series 0.9.1

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2019-10-13 14:51 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-28  8:45 [PATCH 00/11] timed_mutex, shared_timed_mutex: Add full steady clock support Mike Crowe
2019-09-28  8:45 ` [PATCH 05/11] PR libstdc++/78237 Add full steady_clock support to timed_mutex Mike Crowe
2019-09-28  8:45 ` [PATCH 09/11] libstdc++ shared_mutex: Add full steady_clock support to shared_timed_mutex Mike Crowe
2019-09-28  8:45 ` [PATCH 03/11] libstdc++ testsuite: Also test timed_mutex with steady_clock Mike Crowe
2019-09-28  8:45 ` [PATCH 07/11] PR libstdc++/91906 Fix timed_mutex::try_lock_until on arbitrary clock Mike Crowe
2019-10-07  5:25   ` François Dumont
2019-10-13 14:51     ` Mike Crowe
2019-09-28  8:45 ` [PATCH 01/11] libstdc++ testsuite: Check return value from timed_mutex::try_lock_until Mike Crowe
2019-09-28  8:48 ` [PATCH 10/11] libstdc++ timed_mutex: Ensure that try_lock_for waits for long enough Mike Crowe
2019-09-28  8:48 ` [PATCH 06/11] libstdc++ testsuite: Move slow_clock to its own header Mike Crowe
2019-09-28  8:48 ` [PATCH 04/11] libstdc++ testsuite: Also test unique_lock::try_lock_until with steady_clock Mike Crowe
2019-09-28  8:48 ` [PATCH 08/11] libstdc++ testsuite: Also test shared_timed_mutex " Mike Crowe
2019-09-28  8:48 ` [PATCH 02/11] libstdc++ testsuite: Add timed_mutex::try_lock_until test Mike Crowe
2019-09-28  8:48 ` [PATCH 11/11] shared_mutex: Fix try_lock_until and try_lock_shared_until on arbitrary clock Mike Crowe

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).