This is the mail archive of the libc-alpha@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]

Re: why does rwlock prefer readers by default?


On Wed, May 07, 2014 at 12:33:51PM +0200, Torvald Riegel wrote:
> POSIX makes it an implementation-defined choice whether readers or
> writers are preferred.  Our current implementation's default is that
> readers are to be preferred.  I couldn't find the rationale for this;
> does anybody know what it was?
> 
> Otherwise, if this was an arbitrary choice, what do you all think the
> default should be?  Can we change it?  Should we change it to preferring
> writers?

Or do something in between?

>From theoretical perspective always prefering writers is optimal in
sense that it minimizes congestion, if there are multiple readers they
could run on different cores and finish faster. Preffering a writer
will block some readers and decrease throughput.

A reason for prefering writers is different, to avoid a livelock
problems. You could have two reader threads that alternate in locking
causing writers to stall indefinitely.

Then there is alternative of alternating readers and writers to avoid
starvation in both.


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