From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Philip McGrath" Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Add atomic-box-update! function to (ice-9 atomic) Date: Thu, 22 Jun 2023 01:21:27 -0400 Message-ID: <4c24e86e-2dcb-4d41-89c4-67814b6ef4f1@app.fastmail.com> References: <874jn0pxtz.fsf@trop.in> <47D08644-D34F-43C2-9B0C-24A790F3CEA7@abou-samra.fr> <87ttv01711.fsf@trop.in> Mime-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2650"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Cyrus-JMAP/3.9.0-alpha0-499-gf27bbf33e2-fm-20230619.001-gf27bbf33 Cc: guile-devel@gnu.org, "Andy Wingo" To: "Andrew Tropin" , "Jean Abou Samra" Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Thu Jun 22 07:22:32 2023 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qCCm6-0000R3-Ip for guile-devel@m.gmane-mx.org; Thu, 22 Jun 2023 07:22:31 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCClb-00084C-64; Thu, 22 Jun 2023 01:21:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qCClZ-000840-Lz for guile-devel@gnu.org; Thu, 22 Jun 2023 01:21:57 -0400 Original-Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qCClX-00006E-BG for guile-devel@gnu.org; Thu, 22 Jun 2023 01:21:57 -0400 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id D05BA320091C; Thu, 22 Jun 2023 01:21:49 -0400 (EDT) Original-Received: from imap52 ([10.202.2.102]) by compute1.internal (MEProxy); Thu, 22 Jun 2023 01:21:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= philipmcgrath.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1687411309; x=1687497709; bh=H7 5C6J9O3Ienxh5G9WvpQE37S/crLxk+WaEGYbDDDUU=; b=SoXVAUZjwkMYJYT+8/ 2uV/QJZgSJ4I2wivJ0GUv1V+3jN72uythB7Kazlztgy1bsaZ2MXrI1+3ObqyyfyC XSfjaLZkMsvqdDVYsHzmYN6KCoR5Dy0MD3ml69Rze81ErAdDBFuEGfSE3EBrXf1Y 8cjaKIqiYgiO7qv2ac3mLFJb6kaHJlwKrCbMYOctjz81Cp26Km3keLxsJNbUr2CT /m6A/HvTTIOx+k0ZJfJclot3f6OuZu8O55sMf9NUAcqnmn/ATFQX+KEJ0tBOPq2i IgfnMxHu6ppEY9KeGJcqEvupfwqhn7LWRY89SuHJ5AYUM9luYZM7GrrLC6VTP7WS So9g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1687411309; x=1687497709; bh=H75C6J9O3Ienxh5G9WvpQE37S/crLxk+WaE GYbDDDUU=; b=XbiT92Ez3jOcayt6fxmUaEMUeKtWK/xthlxo34oJiOU0sfYAzF9 HOJdSbXWwCN9tv9uBxR5sVR633Fo5e8XUOfDFuv0jAv28KdvVV2BvTerSWunjF7a ExgvTsvjG0bFonfkLd50TBUTREtveTER594HAL5HboVU1mKHy3orTli7zevcuOyV 0Ka924ZomEQ56FZ2xLPx+Wadi3eLUkCtkgQm4XQNLAyWetAUG+G5u8ic3b7Qn8Ol XbzWAv98sM9FcSoQy46wlqglBh/rbtxn0RvH2THWkEt3VGCok1ib1mIouCdiluSG ikctcidMFn4WUinQJlxQHGRCIx1hGvNRGcg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeegtddgkeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtgfesthhqredtreerjeenucfhrhhomhepfdfr hhhilhhiphcuofgtifhrrghthhdfuceophhhihhlihhpsehphhhilhhiphhmtghgrhgrth hhrdgtohhmqeenucggtffrrghtthgvrhhnpeeijeekgeevtdfgjeelgedugeegtedvjedt ffekhedttdetveehtdejieelueduhfenucffohhmrghinheprheirhhsrdhorhhgpdhstg hhvghmvgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhl fhhrohhmpehphhhilhhiphesphhhihhlihhpmhgtghhrrghthhdrtghomh X-ME-Proxy: Feedback-ID: i2b1146f3:Fastmail Original-Received: by mailuser.nyi.internal (Postfix, from userid 501) id 04AE1C60091; Thu, 22 Jun 2023 01:21:49 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface In-Reply-To: <87ttv01711.fsf@trop.in> Received-SPF: pass client-ip=64.147.123.19; envelope-from=philip@philipmcgrath.com; helo=wout3-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:21873 Archived-At: On Wed, Jun 21, 2023, at 11:59 PM, Andrew Tropin wrote: > On 2023-06-21 18:54, Jean Abou Samra wrote: > >>> Le 21 juin 2023 =C3=A0 18:46, Andrew Tropin a =C3=A9= crit : >>>=20 >>> Make sense, but it's hard for me to say something valuable on this >>> topic. Usually, I don't use eq? and don't have enough knowledge of = its >>> internals. >> >> >> *Currently*, it just checks whether the two C-level SCM values are the >> same bitwise, so even implicit copies of fixnums will remain eq?. In >> theory, Guile could make copies of bignums. I am not aware of it doing >> so. >> >> However, all that is guaranteed is that (eq? a a) when a is a >> non-immediate (pair, string, vector, hashtable, etc) or one of a few >> constants like booleans, the empty list and *unspecified*. Notably, it >> isn't guaranteed for numbers or characters. >> > [...] I'm > almost sure that we need eq? here as we need to make sure that the val= ue > previously stored and returned atomic-box-compare-and-swap! is the same > object in memory, however this example from manual is indeed confusing: > > --8<---------------cut here---------------start------------->8--- > (let ((n (+ 2 3))) > (eq? n n)) =3D=3D> _unspecified_ > --8<---------------cut here---------------end--------------->8--- > > So maybe you are right and it's better to use eqv? here. > The problem with eqv? is that it doesn't correspond well to machine-leve= l atomic compare-and-set instructions, so using it would defeat the purp= ose of lightweight atomic boxes. R6RS specifies that "the behavior of eq? on number objects and character= s is implementation-dependent, but it always returns either #t or #f, an= d returns #t only when eqv? would also return #t." [1] I think the right= thing to do here is for Guile to provide more guarantees about its impl= ementation of eq?. Guaranteeing that fixnums are eq? when they are =3D would be particularl= y reasonable and extremely unlikely to cause constrain any future port o= f Guile: the whole point of fixnums is to support efficient machine oper= ations like this. I also think most Schemers would be quite surprised if= (lambda (x) (eq? x x)) ever returned #f. More broadly, *The Scheme Prog= ramming Language* says at the beginning of its documentation for eq? tha= t, "In most Scheme systems, two objects are considered identical if they= are represented internally by the same pointer value and distinct (not = identical) if they are represented internally by different pointer value= s, although other criteria, such as time-stamping, are possible." In any case, the current documentation for atomic-box-compare-and-swap! = is clear that the comparison is eq?: it just means that, when the behavi= or of eq? is unreliable, so is the behavior of atomic-box-compare-and-sw= ap!. Tangentially, does atomic-box-compare-and-swap! handle spurious failures= on architectures like ARM, or does it expose machine semantics to the p= rogrammer? Maybe that's covered by details of the C11 memory model, but = I don't think "sequential consistency" alone is enough to answer the que= stion. -Philip [1]: https://www.r6rs.org/final/html/r6rs/r6rs-Z-H-14.html#node_sec_11.5 [2]: https://scheme.com/tspl4/objects.html#./objects:s10