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
---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster