[Bug nptl/23844] pthread_rwlock_trywrlock results in hang

prohaska7 at gmail dot com sourceware-bugzilla@sourceware.org
Tue Dec 11 18:26:00 GMT 2018


https://sourceware.org/bugzilla/show_bug.cgi?id=23844

--- Comment #10 from richard prohaska <prohaska7 at gmail dot com> ---
(In reply to Torvald Riegel from comment #7)
> (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.

I agree with this patch since it matches the wrlock logic that changes the read
phase to write phase.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Glibc-bugs mailing list