-
Notifications
You must be signed in to change notification settings - Fork 44
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
Miri reported undefined behavior when using ThreadLocal::iter
concurrently from multiple threads.
#70
Comments
Looks like this might be the cause: https://github.com/Amanieu/thread_local-rs/blob/master/src/lib.rs#L220 |
Yep, that's 100% it. According to https://doc.rust-lang.org/nightly/std/sync/atomic/index.html#memory-model-for-atomic-accesses, all unsynchronized operations involving a piece of memory needs to be atomic or non-atomic for behavior to be defined:
|
This looks like it was (fairly recently) defined as undefined behavior, and a data race here: rust-lang/rust#115719. |
Would it fix this if the atomic load is changed to |
I don't think so. The C++20 memory model for atomics, and thus Rust's, do not allow for any form of mixing atomic and non-atomic operations, even if both are reads. Even if in practice, this is probably OK on current platforms, there's zero guarantee this is universally true unless the compiler explicitly defines this behavior. |
That’s not true in C++20. If you read the definition of a data race it requires the actions to be “conflicting”, and actions only conflict if one of them modifies a memory location. Edit: Right, the UB in C++20 comes from TBAA, not data races, which we don’t have in Rust. So in a way we’re introducing UB, but not restricting capabilities. |
Miri seems to report undefined behavior when using
ThreadLocal::iter
from multiple threads concurrently.The code that generated this: https://github.com/james7132/async-executor/blob/master/src/lib.rs#L805. I'll try to make a minimal repro sometime soon.
Full miri log trace.
The text was updated successfully, but these errors were encountered: