I wasn't sure because (- previous-content fx) can be realized by (atomic-fxbox+/fetch! fxbox (- fx)), except the boundary case.    Yet, aligning with stdatomic.h makes more sense.

I wrote tests for srfi-230.  I can make PR for it with the fix of the reference implementation.


On Thu, Nov 14, 2024 at 8:55 PM Marc Nieper-Wißkirchen <xxxxxx@gmail.com> wrote:
Dear Shiro,

Am Do., 14. Nov. 2024 um 23:04 Uhr schrieb Shiro Kawai <xxxxxx@gmail.com>:
>
> The srfi text says the content is set to "the difference of the previous content and fx".   Does it mean (- previous-content fx), (- fx previous-content), or even (abs (- fx previous-content))?
> Reference implementation is (- fx previous-content) . When I read the srfi I took it as (- previous-content fx) so it was a bit of a surprise.  (Maybe I'm conditioned to old CPU's SUB instructions).

You were right when you read it as "(- previous-content fx)". The
sample implementation is wrong.

The SRFI was modelled after the C's <stdatomic.h> (so that it can be
efficiently implemented on architectures that can efficiently
implement the C interface).  The C version of the atomic subtraction
is atomic_fetch_sub.

Thanks,

Marc

>
> The wording can be clarified, e.g. "the subtraction of previous-content from fx"?
>
> --shiro
>
>