This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug nptl/23844] pthread_rwlock_trywrlock results in hang


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]