diff options
| author | Mike Crowe <mac@mcrowe.com> | 2025-11-18 13:06:53 +0000 |
|---|---|---|
| committer | Jonathan Wakely <redi@gcc.gnu.org> | 2025-11-18 17:13:44 +0000 |
| commit | a39fec8c74c8cd58754053dba807d68e2398ca83 (patch) | |
| tree | 0a6cdc42d342302a559aa894e0e143103896477e /libjava/classpath/java/io | |
| parent | c1cf465bdbe587b1ccd8feb05b9b3878163708fe (diff) | |
libstdc++: shared_mutex: Respond consistently to errors and deadlock
Make the shared_mutex::try_lock(), shared_timed_mutex::try_lock_until()
and shared_timed_mutex::try_lock_shared_until() all handle errors from
pthread functions consistently by returning false to indicate that the
lock could not be taken. If _GLIBCXX_ASSERTIONS is defined then
unexpected errors, such as EDEADLK and EINVAL will cause an assertion
failure. If _GLIBCXX_ASSERTIONS is not defined then these functions no
longer ever return true incorrectly indicating that they have taken the
lock.
This removes the previous behaviour of looping on EDEADLK in
try_lock_shared_until() and no longer returns true on EINVAL in all of
these functions. (In theory at least it should not be possible to
trigger EINVAL since 5dba17a3e709859968f939354e6e5e8d796012d3.)
Unfortunately my reading of POSIX is that pthread_rwlock_clockrdlock[1],
pthread_rwlock_timedrdlock pthread_rwlock_clockwrlock[2] and
pthread_rwlock_timedwrlock are allowed to deadlock rather than return
EDEADLK when trying to take a lock a second time from the same
thread. This means that the deadlock tests cannot be enabled by
default. I believe that the tests do work with glibc (2.31 & 2.36) and
with the __shared_mutex_cv implementation though.
[1] https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_rwlock_clockrdlock.html
[2] https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_rwlock_clockwrlock.html
libstdc++-v3/ChangeLog:
* include/std/shared_mutex (try_lock, try_lock_until)
(try_lock_shared_until): Respond consistently to errors and
deadlocks.
* testsuite/30_threads/shared_timed_mutex/try_lock_until/116586.cc:
Test deadlock behaviour if possible.
Signed-off-by: Mike Crowe <mac@mcrowe.com>
Diffstat (limited to 'libjava/classpath/java/io')
0 files changed, 0 insertions, 0 deletions
