On 2023-06-22 17:42, Philip McGrath wrote: > On Thu, Jun 22, 2023, at 5:02 AM, Andrew Tropin wrote: >> On 2023-06-22 01:21, Philip McGrath wrote: >>> >>> 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 behavior of eq? is unreliable, so is the >>> behavior of atomic-box-compare-and-swap!. >> >> Good. Than implementation of atomic-box-update! looks correct to me. >> Any thoughts on including it in (ice-9 atomic)? >> >>> >>> Tangentially, does atomic-box-compare-and-swap! handle spurious >>> failures on architectures like ARM, or does it expose machine >>> semantics to the programmer? Maybe that's covered by details of the >>> C11 memory model, but I don't think "sequential consistency" alone is >>> enough to answer the question. >>> > > I think your implementation is correct. If > atomic-box-compare-and-swap! does not handle spurious failures, I > think your implementation is still correct, but a more efficient > implementation could retry without an extra call to the update > procedure. How? If value was updated you need to recalculate new value. > > Someone with a better sense of Guile performance might have a view > about whether `apply` is likely to be expensive: alternatively, the > update procedure could be restricted to a single argument, or > `case-lambda` could provide a specialized entry-point. Original implementation was a single argument, but I thought that variable number of arguments will be more convinient. -- Best regards, Andrew Tropin