22870, "ronawho", "Stabilize atomic compareAndSwap", "2023-08-03T18:07:29Z"
We currently have similar atomic compareAndSwap and compareExchange methods:
proc compareAndSwap( expected: valType, desired: valType): bool
proc compareExchange(ref expected: valType, desired: valType): bool
Where the difference is that compareExchange takes expected by ref and updates it on failure. This is more efficient when you want to update expected since it avoids having to do another read to get the current value.
compareExchange aligns with the C/C++ compare_exchange_strong API, but is more cumbersome when you don't want to modify expected or you're using non-mutable values. It can also be confusing/surprising that expected gets updated, even for C/C++ users. We decided to stick with the name/behavior to match the C/C++ interface since we based the rest of our atomics off them so we want to stabilize that, but also want a version that doesn't update expected. Currently, that's compareAndSwap, but it's not obvious just from the name which version does what since compareAndSwap and compareExchange are often used interchangeably. For that reason compareAndSwap is currently unstable until we find a better name or decide it's good enough as-is.
For more history/background see compareExchange interface does not match C/C++ · Issue #13836 · chapel-lang/chapel · GitHub and https://github.com/Cray/chapel-private/issues/3730