-
Notifications
You must be signed in to change notification settings - Fork 109
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
Potential to modify ordering for compare_exhange in imp_std module #252
Comments
Oh dear, that’s big if true, thanks! I think the same code has been running in std for the past four years? It does look reasonable on the first glance: that compare exchange is an rmw (read-modify-write) operation, and, if we care to Relase w, we will probably want to Acquire r… The linage of this ordering traces back to rust-lang/rust#65719, where SeqCst orderings were first relaxed. Will take a close look once I properly wake-up 🤣 |
Hm, having properly woken up, I think the code is correct. The reason for that is the call site of this function: Lines 202 to 203 in c48d3c2
We actually don't need |
It appears to be a false positive from my detector. Upon closer examination of the code, I realized that there is no dereferencing operation involved in the Lines 226 to 232 in c48d3c2
It seems that I have to modify the detection pattern😂. |
I agree, Acquire is fine here. |
After lying in bed for a while, I feel much more awake now! The ordering in the code is fine, and I've figured out how to modify the detector pattern. I think we can consider this issue closed. Good night! 😴 |
I developed a static analysis tool to detect issues related to memory ordering, thread performance, and security. During my examination of several crates, I encountered alarms triggered by the following code:
once_cell/src/imp_std.rs
Lines 213 to 232 in c48d3c2
The meaning of the code should be that we need to have a successful initialization operation in Line222, but the compare exchange also entails reading the atomic pointer to the
exchange
. Therefore, it's necessary to useAcqRel
andAcquire
to observe any other modifications to the memory that the atomic pointer references, both when the compare exchange succeeds and when it fails.I think compare exchange for
queue
usesAcqRel
for the success case andAcquire
for the fail case.(happy to make a PR if this looks reasonable)
The text was updated successfully, but these errors were encountered: