-
Notifications
You must be signed in to change notification settings - Fork 186
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
use_file: Use Acquire/Release semantics instead of Relaxed. #469
use_file: Use Acquire/Release semantics instead of Relaxed. #469
Conversation
I am convinced that relaxed ordering is OK because the mutex should give us acquire/release semantics for the store and prevent double initialization. Atomic ordering is about controlling how non-atomic variables are viewed by other threads, so having only a single AtomicUsize make this easier. Relaxed atomics are consistent with themselves, so if a thread sees an initialized fd from a relaxed load, it will never see an uninitialized value from future loads. I sketched out the memory ordering of two racing threads, where one thread wins and initializes the AtomicUsize and the other thread will see the memory write after locking the mutex
I can see that with relaxed atomics a thread may try to take the lock when the FD is initialized, but it will not write a new value. |
I filed rust-lang/rust#126239 last week exactly to get it clarified, using this library's code as the motivating example. |
To clarify, the issue isn't about the value in |
I think we can safely ignore any such unusual
In my understanding, none of the targets covered by |
All of the sanitizers write unsynchronized state whenever |
Hm, in this case I think we have to use |
878dd7b
to
fa93ab2
Compare
See the added comment for details. I don't know if this is really an issue but I couldn't convince myself that it isn't ever.
fa93ab2
to
aae32e5
Compare
I rebased this on top of master, copy-edited the comment a bit, and also added a comment about the purpose of the Mutex. |
See the added comment for details. I don't know if this is really an issue but I couldn't convince myself that it isn't ever.