On 2014-02-10 11:11:28 -0500, Tom Lane wrote:
> Andres Freund <and...@2ndquadrant.com> writes:
> > So what we need to do is to acquire a write barrier between the
> > assignments to lwWaitLink and lwWaiting, i.e.
> >         proc->lwWaitLink = NULL;
> >         pg_write_barrier();
> >         proc->lwWaiting = false;
> 
> You didn't really explain why you think that ordering is necessary?
> Each proc being awoken will surely see both fields updated, and other
> procs won't be examining these fields at all, since we already delinked
> all these procs from the LWLock's queue.

The problem is that one the released backends could wake up concurrently
because of a unrelated, or previous PGSemaphoreUnlock(). It could see
lwWaiting = false, and thus wakeup and acquire the lock, even if the
store for lwWaitLink hasn't arrived (or performed, there's no guaranteed
ordering here) yet.
Now, it may well be that there's no practical consequence of that, but I
am not prepared to bet on it.

Greetings,

Andres Freund

-- 
 Andres Freund                     http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to