Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 57F1E632F0D for ; Wed, 20 Jan 2010 14:49:20 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 78657-10 for ; Wed, 20 Jan 2010 18:49:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og103.obsmtp.com (exprod7og103.obsmtp.com [64.18.2.159]) by mail.postgresql.org (Postfix) with SMTP id 43AD16326B5 for ; Wed, 20 Jan 2010 14:49:09 -0400 (AST) Received: from source ([209.85.219.211]) by exprod7ob103.postini.com ([64.18.6.12]) with SMTP ID DSNKS1dQJGYckxwEzPlFyogr7uCcACe7RHR/@postini.com; Wed, 20 Jan 2010 10:49:09 PST Received: by ewy3 with SMTP id 3so1867956ewy.33 for ; Wed, 20 Jan 2010 10:49:07 -0800 (PST) Received: by 10.213.1.131 with SMTP id 3mr312385ebf.34.1264013347182; Wed, 20 Jan 2010 10:49:07 -0800 (PST) Received: from ?192.168.1.117? ([88.195.103.165]) by mx.google.com with ESMTPS id 23sm254650eya.27.2010.01.20.10.49.05 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 20 Jan 2010 10:49:06 -0800 (PST) Message-ID: <4B57501F.8030804@enterprisedb.com> Date: Wed, 20 Jan 2010 20:49:03 +0200 From: Heikki Linnakangas Organization: EnterpriseDB User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090706) MIME-Version: 1.0 To: Tom Lane CC: Andres Freund , Simon Riggs , pgsql-hackers@postgresql.org, Hiroyuki Yamada Subject: Re: Synchronization primitives (Was: Re: An example of bugs for Hot Standby) 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> In-Reply-To: <16135.1264011365@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201001/2001 X-Sequence-Number: 155222 Tom Lane wrote: > Heikki Linnakangas 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