This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug nptl/23844] pthread_rwlock_trywrlock results in hang
- From: "triegel at redhat dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Tue, 11 Dec 2018 15:28:29 +0000
- Subject: [Bug nptl/23844] pthread_rwlock_trywrlock results in hang
- Auto-submitted: auto-generated
- References: <bug-23844-131@http.sourceware.org/bugzilla/>
https://sourceware.org/bugzilla/show_bug.cgi?id=23844
--- Comment #7 from Torvald Riegel <triegel at redhat dot com> ---
(In reply to richard prohaska from comment #5)
> 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.
I agree with your analysis of what the root cause is, but the fix you propose
isn't correct.
trywrlock needs to install a write-phase, but only in some cases. Essentially,
this is:
- atomic_store_relaxed (&rwlock->__data.__wrphase_futex, 1);
+ /* If we started a write phase, we need to enable readers to
+ wait. If we did not, we must not change it because other threads
+ may have set the PTHREAD_RWLOCK_FUTEX_USED in the meantime. */
+ if ((r & PTHREAD_RWLOCK_WRPHASE) == 0)
+ atomic_store_relaxed (&rwlock->__data.__wrphase_futex, 1);
I haven't looked at your tryrdlock case yet.
--
You are receiving this mail because:
You are on the CC list for the bug.