guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Add atomic-box-update! function to (ice-9 atomic)


From: Andrew Tropin
Subject: Re: [PATCH] Add atomic-box-update! function to (ice-9 atomic)
Date: Thu, 22 Jun 2023 07:59:38 +0400

On 2023-06-21 18:54, Jean Abou Samra wrote:

>> Le 21 juin 2023 à 18:46, Andrew Tropin <andrew@trop.in> a écrit :
>> 
>> 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 went the way suggested by the manual: "Returns the
>> previous value of the box in either case, so you can know if the swap
>> worked by checking if the return value is eq? to expected."
>> 
>> https://www.gnu.org/software/guile/manual/html_node/Atomics.html
>
>
> As long as you use boxes for values for which eq? is well-defined,
> that is fine. I guess this would cover most cases, although I'm not
> familiar with this module.

We don't compare boxes here, we compare the underlying values.  I'm
almost sure that we need eq? here as we need to make sure that the value
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))                           ==>  _unspecified_
--8<---------------cut here---------------end--------------->8---

So maybe you are right and it's better to use eqv? here.

-- 
Best regards,
Andrew Tropin

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]