You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
We currently have similar atomic
compareAndSwap
andcompareExchange
methods:Where the difference is that
compareExchange
takesexpected
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 thatexpected
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 updateexpected
. Currently, that'scompareAndSwap
, but it's not obvious just from the name which version does what sincecompareAndSwap
andcompareExchange
are often used interchangeably. For that reasoncompareAndSwap
is currently unstable until we find a better name or decide it's good enough as-is.For more history/background see #13836 and https://github.com/Cray/chapel-private/issues/3730
The text was updated successfully, but these errors were encountered: