Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize atomic compareAndSwap #22870

Open
ronawho opened this issue Aug 3, 2023 · 0 comments
Open

Stabilize atomic compareAndSwap #22870

ronawho opened this issue Aug 3, 2023 · 0 comments

Comments

@ronawho
Copy link
Contributor

ronawho commented Aug 3, 2023

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 #13836 and https://github.com/Cray/chapel-private/issues/3730

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants