Re: Synchronization primitives (Was: Re: An example of bugs for Hot Standby) - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: Synchronization primitives (Was: Re: An example of bugs for Hot Standby)
Date
Msg-id 4B57501F.8030804@enterprisedb.com
Whole thread Raw
In response to Re: Synchronization primitives (Was: Re: An example of bugs for Hot Standby)  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Synchronization primitives (Was: Re: An example of bugs for Hot Standby)  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Tom Lane wrote:
> Heikki Linnakangas <heikki.linnakangas@enterprisedb.com> writes:
>> Streaming Replication introduces a few places with a polling pattern
>> like this (in pseudocode):
> 
>> while()
>> {
>>   /* Check if variable in shared has advanced beoynd X */
>>   SpinLockAcquire()
>>   localvar = sharedvar;
>>   SpinLockRelease()
>>   if (localvar > X)
>>     break;
> 
>>   /* Not yet. Sleep
>>   pg_usleep(100);
>> }
> 
> I trust there's a CHECK_FOR_INTERRUPTS in there ...
> 
>> It would be nice to have a new synchronization primitive for that.
> 
> Maybe.  The lock, the variable, the comparison operation, and the sleep
> time all seem rather specific to each application.  Not sure that it'd
> really buy much to try to turn it into a generic subroutine.

My point is that we should replace such polling loops with something
non-polling, using wait/signal or semaphores or something. That gets
quite a bit more complex. You'd probably still have the loop, but
instead of pg_usleep() you'd call some new primitive function that waits
until the shared variable changes.

--  Heikki Linnakangas EnterpriseDB   http://www.enterprisedb.com


pgsql-hackers by date:

Previous
From: Simon Riggs
Date:
Subject: Re: An example of bugs for Hot Standby
Next
From: Tom Lane
Date:
Subject: Re: Synchronization primitives (Was: Re: An example of bugs for Hot Standby)