-
Notifications
You must be signed in to change notification settings - Fork 111
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
Atomic operations on part of an atomic integer? #295
Comments
AFAIK, for Miri, mixed-size access is considered an open issue rather than a supported operation: rust-lang/unsafe-code-guidelines#345 In fact, when I run your example in multi-threaded, Miri reports an error that the operation is not supported.
|
Thanks for the reference and counterexample! Looks like loom steered me in the right direction here, at least while it's still an open issue in Rust itself. |
Yeah, the only reason your original code works is that they don't happen in parallel. I don't think we are going to support this unless std defines the behavior. |
It'd be useful to be able to perform atomic operations on parts of atomic integer in addition to the whole thing.
e.g. the following runs as expected, including under miri:
This isn't valid using loom's atomics, since they aren't
repr(transparent)
wrappers around the underlying integer types.Is there some way that miri atomics might be able to support this?
As a motivating example, I'm implementing a mutex, and would like to be keep the locked/unlocked state, and the number of threads sleeping on the mutex, in a 64 bit integer, in the individual 32 bit pieces. I'd like to be able to e.g. compare and swap the mutex state without caring about the number of sleepers when locking, while still being able to atomically unlock and get the sleeper count when unlocking.
The text was updated successfully, but these errors were encountered: