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 1tqtpN-00Bleg-Fb for pgsql-hackers@arkaria.postgresql.org; Sat, 08 Mar 2025 13:02:53 +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 1tqtpK-00HY2H-Np for pgsql-hackers@arkaria.postgresql.org; Sat, 08 Mar 2025 13:02:50 +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 1tqtpJ-00HXvw-KR for pgsql-hackers@lists.postgresql.org; Sat, 08 Mar 2025 13:02:50 +0000 Received: from fout-b8-smtp.messagingengine.com ([202.12.124.151]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tqtpE-001gT4-2n for pgsql-hackers@postgresql.org; Sat, 08 Mar 2025 13:02:49 +0000 Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.stl.internal (Postfix) with ESMTP id 8925B11400EE; Sat, 8 Mar 2025 08:02:43 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Sat, 08 Mar 2025 08:02:43 -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=1741438963; x=1741525363; bh=s4df6GSfK0 vfl6SPbgEwTBpqmNDAYb0E0YGIOVStOTU=; b=TrFWyfzZqC7PMs1E+rMlAgSz12 CccY4DqjlLdxtMTJYd98VhogL6NrgPq5aR3rMTEh2vhFW4GeoOih1fWf10//tUlB p316ov4jm+TjwHjPbAmFZFb9W+yWjnef2BuJl0r8r3jovb9Tfpx6pUegSzBmGOuv EmTJJgi8zIjSuiRO5yORdaJrIdmeITQbEhYm56f5tGzCudhlYB/alpCqdjy0QbjI fReqIAj61Hp67XR6rMnprAYM3bkoLUOZLtGz1QJDQ3waCVJ3SJllorrtzuogaJhn 0db3XwoLusCH/iurzTZAuu1cKW2EN/Sz7mINdk5+n4RGjotxNcProHS3tq1A== 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= 1741438963; x=1741525363; bh=s4df6GSfK0vfl6SPbgEwTBpqmNDAYb0E0YG IOVStOTU=; b=ZMJMYhxAVj/4Xjwn1sv2b61vsHERUuKo1I+1B8tUbUtmlmg45tW TXGaECqBTo8sUqnrBsC0UGapOmIN4RLqUXi/PSOuVWSGeHTzqv5bRK4JwhBj8Sxe Psd3otAiw/Wq+SOySeDAGuPNGlkTuxJTvNtKJIj2kAlGaM+o8la1vvPSQFABBuyv w9HFgZLpXfrn1z+hg/6+R9S1RTESSX5nB9dPJxuRZ4tpNXXRYsV5R4w0dh/JoM3X wTLEplF3lSqIzJN7G+FrAJz/wPwXpINEdewpjPcXRaG/nVHBoFhKRDDf1EOEQjPv 0YesdFdTrGIstOTyCzE5e49M8BHrbVGP+kg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduudefiedvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtsfdttddt vdenucfhrhhomheptehnughrvghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrg iivghlrdguvgeqnecuggftrfgrthhtvghrnhepgfeuleejleegveeiueeiheetieejueeg jeevvedvgeevfffhffdtgeekleduueffnecuffhomhgrihhnpehgnhhurdhorhhgnecuve hluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghnughrvghs segrnhgrrhgriigvlhdruggvpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpoh huthdprhgtphhtthhopegrvghkohhrohhtkhhovhesghhmrghilhdrtghomhdprhgtphht thhopehpghhsqhhlqdhhrggtkhgvrhhssehpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 8 Mar 2025 08:02:42 -0500 (EST) Date: Sat, 8 Mar 2025 08:02:41 -0500 From: Andres Freund To: Alexander Korotkov Cc: pgsql-hackers Subject: Re: pg_atomic_compare_exchange_*() and memory barriers Message-ID: <6ybtypq2v3kvskiqj7izl2rmfrcluilsmbobtpylcnp7moa7vq@2q3cplokvcza> References: <2muwyx6a5vojkg7iegknhnkcch3lfxptsxk7icwuh7szkvvu2y@vc3ukkfvnu6i> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2025-03-08 14:12:13 +0200, Alexander Korotkov wrote: > I'm not an expert in formal specifications of memory models. But I'm quite > surprised we're discussing whether memory barrier on compare-exchange > failure might matter. For me at least the fact > that __atomic_compare_exchange_n() have failure_memorder argument is a > quite an evidence of that. I wasn't trying to say that the failure memory order doesn't matter, just that an *acquire* barrier might be strong enough in the failure case if you look at it from the POV of C++/C11's memory model. The docs for __atomic_compare_exchange_n say: https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html#index-_005f_005fatomic_005fcompare_005fexchange_005fn > Otherwise, false is returned and memory is affected according to > failure_memorder. This memory order cannot be __ATOMIC_RELEASE nor > __ATOMIC_ACQ_REL. It also cannot be a stronger order than that specified by > success_memorder. Note that the generated code you showed *did* unconditionally execute the load with acquire semantics. Which means that that one can argue that this is *NOT* a compiler bug.