[Bug nptl/23844] pthread_rwlock_trywrlock results in hang
prohaska7 at gmail dot com
sourceware-bugzilla@sourceware.org
Tue Dec 11 14:16:00 GMT 2018
https://sourceware.org/bugzilla/show_bug.cgi?id=23844
--- Comment #5 from richard prohaska <prohaska7 at gmail dot com> ---
The futex waits on the wrphase futex occur because the 'USED' flag is being
discarded by the 'trywrlock' function. Since the 'USED' flag is discarded, the
'wrunlock' function will not wake the futex when the rwlock is released. This
causes other threads waiting for the rwlock to hang.
The 'wrlock' function does the following on an uncontended lock that is already
in the write phase. (1) the WL bit is atomically set, (2) if the WL was not
previously set then this thread holds the exclusive write lock (3) the writers
futex is set to 1, and finally (4) the cur_writer is set. Note that the
wrphase futext is not changed in this 'wrlock' code path.
Unfortunately, the 'trywrlock' function ALSO sets the wrphase futex = 1. This
is racy with the contended lock code paths in the 'rdlock' and 'wrlock'
functions, and can cause the 'USED' bit to be lost.
The patch just removes the code in 'trywrlock' that sets the wrphase futex to
match the 'wrlock' fast path logic. This patch passes the included test cases.
diff --git a/nptl/pthread_rwlock_trywrlock.c b/nptl/pthread_rwlock_trywrlock.c
index 5a73eba756..b423648ad6 100644
--- a/nptl/pthread_rwlock_trywrlock.c
+++ b/nptl/pthread_rwlock_trywrlock.c
@@ -47,7 +47,6 @@ __pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock)
r | PTHREAD_RWLOCK_WRPHASE | PTHREAD_RWLOCK_WRLOCKED))
{
atomic_store_relaxed (&rwlock->__data.__writers_futex, 1);
- atomic_store_relaxed (&rwlock->__data.__wrphase_futex, 1);
atomic_store_relaxed (&rwlock->__data.__cur_writer,
THREAD_GETMEM (THREAD_SELF, tid));
return 0;
I have also seen thread hangs when only using 'tryrdlock' (not 'trywrlock') in
these test cases. This indicates that there is also a problem in the
'tryrdlock' function.
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the Glibc-bugs
mailing list