core.stdc.stdatomic
IGotD-
nise at nise.com
Fri Nov 17 12:41:39 UTC 2023
On Friday, 17 November 2023 at 10:25:31 UTC, claptrap wrote:
>
> What instructions the compiler inserts around the CAS
> instruction are irrelevant, none of what they do can break the
> CAS.
It is not irrelevant. You cannot break the CAS itself as it is
usually implemented according to the SW ABI of the architecture.
However, you must instruct the compiler so that reordering
optimizations don't spill over the CAS implementations. If
optimizations make instructions spill over to the wrong side of
the CAS, then you possibly will end up in a non working algorithm.
So you not only perhaps need to insert a memory barrier
instruction depending on ISA, you also need to instruct the
compiler not to trespass the atomic instructions. This is usually
implicit as atomic operations are implemented as intrinsics which
automatically do this for you.
More information about the Digitalmars-d
mailing list