Visa Hankala wrote: > On Sat, Mar 02, 2019 at 10:29:07AM +0100, Sebastien Marie wrote: > > I am experiencing dead-lock with the new futex based rwlock > > implementation commited few days ago. > > The problem happens if a read-write lock has been read-locked and > there are multiple writers waiting. The unlock routine will clear the > waiter flag and wake up a single waiter. If no new waiters emerge > before the next unlock, no wakeup will be issued. > > A simple fix is to wake all waiters, so that no wakeup is lost. > That may cause a thundering herd effect with writers though. The > implementation could encode the number of waiters in `rwlock->value', > enabling more discreet wakeups. However, that needs more testing. > > Does the following patch help?
This looks ok to me. > > Index: rthread_rwlock.c > =================================================================== > RCS file: src/lib/librthread/rthread_rwlock.c,v > retrieving revision 1.12 > diff -u -p -r1.12 rthread_rwlock.c > --- rthread_rwlock.c 13 Feb 2019 13:22:14 -0000 1.12 > +++ rthread_rwlock.c 2 Mar 2019 13:35:31 -0000 > @@ -273,7 +273,7 @@ pthread_rwlock_unlock(pthread_rwlock_t * > } while (atomic_cas_uint(&rwlock->value, val, new) != val); > > if (new == UNLOCKED && (val & WAITING)) > - _wake(&rwlock->value, COUNT(val)); > + _wake(&rwlock->value, INT_MAX); > > return (0); > } >