Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 70DAC16B0CAE for ; Mon, 19 Dec 2011 16:21:43 -0400 (AST) Received: from exprod7og111.obsmtp.com ([64.18.2.175]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RcjiN-0008F9-SW for pgsql-bugs@postgresql.org; Mon, 19 Dec 2011 20:21:43 +0000 Received: from mail-ee0-f52.google.com ([74.125.83.52]) (using TLSv1) by exprod7ob111.postini.com ([64.18.6.12]) with SMTP ID DSNKTu+cxo56r72SN2Fq2UXTGt+UiXVFms8E@postini.com; Mon, 19 Dec 2011 12:21:39 PST Received: by eeke52 with SMTP id e52so5181629eek.25 for ; Mon, 19 Dec 2011 12:21:25 -0800 (PST) Received: by 10.213.27.68 with SMTP id h4mr2966271ebc.107.1324326085554; Mon, 19 Dec 2011 12:21:25 -0800 (PST) Received: from [192.168.1.101] (dsl-hkibrasgw2-ff6cc300-200.dhcp.inet.fi. [88.195.108.200]) by mx.google.com with ESMTPS id z43sm48832416eef.7.2011.12.19.12.21.23 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 19 Dec 2011 12:21:24 -0800 (PST) Message-ID: <4EEF9CC2.9080909@enterprisedb.com> Date: Mon, 19 Dec 2011 22:21:22 +0200 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fi-FI; rv:1.9.2.24) Gecko/20111114 Icedove/3.1.16 MIME-Version: 1.0 To: Noah Misch CC: Robert Haas , PostgreSQL Bugs Subject: Re: [PATCH] Use CC atomic builtins if available [was: Re: TAS patch for building on armel/armhf thumb] References: <4EEB1C77.1000309@enterprisedb.com> <20111218224203.GA2950@piware.de> <4EEF5397.8090200@enterprisedb.com> <20111219200341.GB9495@tornado.leadboat.com> In-Reply-To: <20111219200341.GB9495@tornado.leadboat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201112/163 X-Sequence-Number: 31974 On 19.12.2011 22:03, Noah Misch wrote: > On Mon, Dec 19, 2011 at 05:09:11PM +0200, Heikki Linnakangas wrote: >> Actually, I believe our Itanium (and possibly ARM, too) implementation >> of S_UNLOCK() is wrong as it is. There is no platform-specific >> S_UNLOCK() defined for Itanium, so we're using the generic >> implementation: >> >> #if !defined(S_UNLOCK) >> #define S_UNLOCK(lock) (*((volatile slock_t *) (lock)) = 0) >> #endif /* S_UNLOCK */ >> >> That is not sufficient on platforms with a weak memory model, like Itanium. > > Other processors may observe the lock as held after its release, but there's no > correctness problem. I thought it would also be legal for a store to become visible to other processors, *after* the releasing of the lock. Which would be bad. For example, if you have: volatile bool *shared = ... SpinLockAcquire(lock); shared->variable = true; SpinLockRelease(lock); more code The macro-expanded code would look like: lock shared->variable = true; (*((volatile slock_t *) (lock)) = 0; more code I believe on an architecture with a weak memory model, like Itanium, there's no guarantee that the assignments will happen in that order. The lock might appear as released *before* the variable is set. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com