Re: lwlocks and starvation - Mailing list pgsql-hackers

From Neil Conway
Subject Re: lwlocks and starvation
Date
Msg-id 41A483FB.9070106@samurai.com
Whole thread Raw
In response to Re: lwlocks and starvation  (Bruce Momjian <pgman@candle.pha.pa.us>)
Responses Re: lwlocks and starvation  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: lwlocks and starvation  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: lwlocks and starvation  (Simon Riggs <simon@2ndquadrant.com>)
List pgsql-hackers
Bruce Momjian wrote:
> I thought the new readers will sit after the writer in the FIFO queue so
> the writer will not starve.

AFAICS, that is not the case. See lwlock.c, circa line 264: in LW_SHARED 
mode, we check if "exclusive" is zero; if so, we acquire the lock 
(increment the shared lock count and do not block). And "exclusive" is 
set non-zero only when we _acquire_ a lock in exclusive mode, not when 
we add an exclusive waiter to the wait queue.

(Speaking of which, the "exclusive" field is declared as a "char"; I 
wonder if it wouldn't be more clear to declare it as "bool", and treat 
it as a boolean field. The storage/alignment requirements should be the 
same (bool is a typedef for char, at least a C compiler), but IMHO it 
would be more logical.)

-Neil


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: lwlocks and starvation
Next
From: Neil Conway
Date:
Subject: Re: -V, --version -- deprecated?