pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Andres Freund <andres@anarazel.de>
Cc: Simon Riggs <simon@2ndquadrant.com>
Cc: pgsql-hackers@postgresql.org, Hiroyuki Yamada <yamada@kokolink.net>
Subject: Re: Synchronization primitives (Was: Re: An example of bugs for Hot Standby)
Date: Wed, 20 Jan 2010 20:49:03 +0200
Message-ID: <4B57501F.8030804@enterprisedb.com> (raw)
In-Reply-To: <16135.1264011365@sss.pgh.pa.us>
References: <200912151111.AA00168@silver.kokolink.net>
	<201001201740.22069.andres@anarazel.de>
	<14578.1264006776@sss.pgh.pa.us>
	<201001201841.15760.andres@anarazel.de>
	<4B5744C1.40806@enterprisedb.com>
	<16135.1264011365@sss.pgh.pa.us>

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



view thread (8+ messages)  latest in thread

Message-ID: <4B57501F.8030804@enterprisedb.com>
Permalink:  ../4B57501F.8030804@enterprisedb.com/
Also on:    postgresql.org/message-id/4B57501F.8030804@enterprisedb.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: heikki.linnakangas@enterprisedb.com, tgl@sss.pgh.pa.us, andres@anarazel.de, simon@2ndquadrant.com, yamada@kokolink.net
  Subject: Re: Synchronization primitives (Was: Re: An example of bugs for Hot Standby)
  In-Reply-To: <4B57501F.8030804@enterprisedb.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox