[PATCH v2] rwlock: prevent readers from starving writers

Stephen Hemminger stephen at networkplumber.org
Wed Jul 20 00:33:41 CEST 2022


> >  /**
> > @@ -179,7 +226,7 @@ rte_rwlock_write_lock(rte_rwlock_t *rwl)
> >  static inline void
> >  rte_rwlock_write_unlock(rte_rwlock_t *rwl)
> >  {
> > -	__atomic_store_n(&rwl->cnt, 0, __ATOMIC_RELEASE);
> > +	__atomic_fetch_sub(&rwl->cnt, RTE_RWLOCK_WRITE,
> > __ATOMIC_RELEASE);  
> 
> Yes. This is correct, regardless if another writer thread is waiting or not. (Reviewed for one writer thread using rte_rwlock_write_lock() and another using rte_rwlock_write_trylock().)
> 

Was trying to stick to original logic.

After writer releases want both writer and reader to be able to get in equally.
This provide a measure of fairness (no preference) so writers can't starve readers either.


More information about the dev mailing list