Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tquQo-00Bsei-FW for pgsql-hackers@arkaria.postgresql.org; Sat, 08 Mar 2025 13:41:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tquQl-000hHc-2T for pgsql-hackers@arkaria.postgresql.org; Sat, 08 Mar 2025 13:41:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tquQk-000hFl-O9 for pgsql-hackers@lists.postgresql.org; Sat, 08 Mar 2025 13:41:30 +0000 Received: from fhigh-b1-smtp.messagingengine.com ([202.12.124.152]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tquQg-001gou-2b for pgsql-hackers@postgresql.org; Sat, 08 Mar 2025 13:41:30 +0000 Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.stl.internal (Postfix) with ESMTP id 2AA1E254018D; Sat, 8 Mar 2025 08:41:26 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Sat, 08 Mar 2025 08:41:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1741441286; x=1741527686; bh=XrzowodFyd Vx1gN2+Jly1qxGolzubRP1Bv40/jPIhWI=; b=Ln2MSlCn73KKoKvFP4IQmug6fK W3Mblo1uAVs6G1ZLNKy+FaXaflFlD8qF16Ds9ICukIyHNXXPPfBny937E2jC21Bc FXSu24es5YJ7V0luJd4BotzDspwBDHi6IFWZKx1Og0aLGHHZUDDpuiFL/5uHqTm4 y7K5ikZWRawqkzqc8fWrpMzqviaWOy9rlBeQl6C7tz4I2vFy3iD1//G9bmHer0mJ HJ6Se4qLIrJDP/Q2IlP5uAm3IvICZrki2XxKerIlNUMlUYKNz2YJOxvBgZySLytf 3tkmHMAl3JiYLMT2EfZ6+7e5RDC+m2TA02UkoCghSuSlNdArvdt/eTGwb7Dg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1741441286; x=1741527686; bh=XrzowodFydVx1gN2+Jly1qxGolzubRP1Bv4 0/jPIhWI=; b=N1+j7aPBVL3uv/3fOj+ePhQIHOqMsT/Lzf5V5/Y0D6oq3zyOpgQ ka/rRWYe5jIVAUngsinZswJOeK3LhPBToTSLpHSfeXJyb+0CEjtpXjVspXFrjqx2 o4ODGKQu+nNVbN2u8LsdFSB39o0HbwhwR/Ea9eEhuOMw3l8hQoWFfoEl28ayNevr lhQp9JmP6VRXiNXficwZFAasrNaZheZnUYcJKvZF8SrQC28Ym/+iZ5AfAou0GVZ3 pYIW4uNoDCsnQpIEImzgfD+rQ+y2gdID8tFQGHVOYrk5mu4o8J81p422m4eIY0Fn zKjn6/J+NjHIsEtYt4hMlhudWxiSM2Mvyeg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduudefjedtucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtsfdttddt vdenucfhrhhomheptehnughrvghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrg iivghlrdguvgeqnecuggftrfgrthhtvghrnhepfeffgfelvdffgedtveelgfdtgefghfdv kefggeetieevjeekteduleevjefhueegnecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomheprghnughrvghssegrnhgrrhgriigvlhdruggvpdhnsggp rhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopegrvghkohhroh htkhhovhesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhs sehpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 8 Mar 2025 08:41:25 -0500 (EST) Date: Sat, 8 Mar 2025 08:41:24 -0500 From: Andres Freund To: Alexander Korotkov Cc: pgsql-hackers Subject: Re: pg_atomic_compare_exchange_*() and memory barriers Message-ID: References: <2muwyx6a5vojkg7iegknhnkcch3lfxptsxk7icwuh7szkvvu2y@vc3ukkfvnu6i> <6ybtypq2v3kvskiqj7izl2rmfrcluilsmbobtpylcnp7moa7vq@2q3cplokvcza> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6ybtypq2v3kvskiqj7izl2rmfrcluilsmbobtpylcnp7moa7vq@2q3cplokvcza> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2025-03-08 08:02:41 -0500, Andres Freund wrote: > From the C/C++ standard atomics model it doesn't make sense to say that a > failed CAS has release semantics, as there simply isn't a write that could be > ordered! What their barriers guarantee is ordering between multiple memory > operation, you can't order multiple writes if you don't have multiple > writes... The synchronization in the C/C++ model is only established between > accesses of the same variable and there's no write in the case of a failed > CAS, so there's nothing that could establish a release-acquire ordering. > > Unfortunately that model doesn't mesh well with barriers that aren't attached > to read/modify operations. Which is what we ended up with... Adding a full barrier to failed CAS would be a rather large overhead, undesirable in just about any sane algorithm. As a consequence, I think what we ought to do is to redefine the barrier semantics to only imply an acquire barrier in case CAS fails. Greetings, Andres Freund