-
Notifications
You must be signed in to change notification settings - Fork 13.3k
could std::intrinsics::atomic_max be exposed via an AtomicUsize::fetch_max method? #48384
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
Comments
Note that if the hardware does not support atomic max, this is expanded to a CAS loop regardless. At least on the default x86_64 target that is the case (see playground). |
Ahh yeah, even with
Anyway, I think introducing a |
This adds a new method to all numeric `Atomic*` types with a safe compare-and-set loop, so users will no longer need to write their own, except in *very* strange circumstances. This solves rust-lang#48384 with `x.fetch_max(_)`/`x.fetch_min(_)`. It also relates to rust-lang#48655 (which I misuse as tracking issue for now). *note* This *might* need a crater run because the functions could clash with third party extension traits.
Add a generic CAS loop to std::sync::Atomic* This adds two new methods to both `AtomicIsize` and `AtomicUsize` with optimized safe compare-and-set loops, so users will no longer need to write their own, except in *very* strange circumstances. `update_and_fetch` will apply the function and return its result, whereas `fetch_and_update` will apply the function and return the previous value. This solves rust-lang#48384 with `x.update_and_fetch(|x| x.max(y))`. It also relates to rust-lang#48655 (which I misuse as tracking issue for now).. *note* This *might* need a crater run because the functions could clash with third party extension traits.
This has since been added (#48655). |
As part of my recent work on supporting transactions in sled I've wanted to take advantage of the
atomic_max
intrinsic so that I can implement a lock-free concurrency control protocol more efficiently, without spinning on CAS in a loop. It would be wonderful if I could do this without relying on compiling C. Specifically, updating the read timestamp of an item read in an MVOCC transaction, where read items need to be marked as having been read "at least as high as" a transaction timestamp being executed by a particular thread.Are there any blockers to adding this? I'm happy to write the code that exposes it if not.
The text was updated successfully, but these errors were encountered: