Re: releaseOk and LWLockWaitForVar - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: releaseOk and LWLockWaitForVar
Date
Msg-id 53A857DE.9000900@vmware.com
Whole thread Raw
In response to releaseOk and LWLockWaitForVar  (Andres Freund <andres@2ndquadrant.com>)
List pgsql-hackers
On 06/17/2014 03:17 PM, Andres Freund wrote:
> LWLockWaitForVar() doesn't set releaseOk to true when waiting
> again. Isn't that a bug?

LWLockWaitForVar() waits in LW_WAIT_UNTIL_FREE mode, because it's not 
interested in acquiring the lock, it just wants to be woken up when it's 
released (or the "var" is updated). LWLockRelease doesn't clear 
releaseOK when it wakes up a LW_WAIT_UNTIL_FREE-mode waiter.

> What if there's another locker coming in after
> LWLockWaitForVar() returns from the PGSemaphoreLock() but before it has
> acquire the spinlock? Now, it might be that it's unproblematic because
> of hte specific way these locks are used right now, but it doesn't seem
> like a good idea to leave it that way.

In that scenario, LWLockWaitForVar() will grab the spinlock, after the 
other process. What happens next depends on the whether the value of the 
variable it guards was changed. If it was, LWLockWaitForVar() will see 
that it changed, and return false without waiting again. If the value 
didn't change, it will sleep until the new locker releases the lock. In 
either case, I don't see a problem with releaseOK. It seems correct as 
it is.

- Heikki




pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: API change advice: Passing plan invalidation info from the rewriter into the planner?
Next
From: Andres Freund
Date:
Subject: Re: Atomics hardware support table & supported architectures