-
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
Atomics load with SeqCst ordering strange behaviour #180
Comments
Lines 31 to 34 in 21db3cc
Lines 276 to 280 in 21db3cc
It seems that loom is not handling SeqCst load yet. |
Hi all, Thanks a lot for this incredible test framework. My colleagues and I use However, it turns out that it does not implement the use loom::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::SeqCst;
let model = loom::model::Builder::new();
model.check(|| {
let data: Arc<AtomicUsize> = Arc::new(AtomicUsize::default());
let t1: Arc<AtomicUsize> = Arc::new(AtomicUsize::default());
let t2: Arc<AtomicUsize> = Arc::new(AtomicUsize::default());
let data_cloned = data.clone();
let t1_cloned = t1.clone();
let t2_cloned = t2.clone();
let thread_handle = loom::thread::spawn(move || {
t2_cloned.store(1, SeqCst);
if t1_cloned.load(SeqCst) == 0 {
data_cloned.fetch_add(1, SeqCst);
}
});
t1.store(1, SeqCst);
if t2.load(SeqCst) == 0 {
data.fetch_add(1, SeqCst);
}
drop(thread_handle.join());
assert!(data.load(SeqCst) < 2);
}); I guess, the lack of correct implementation of |
I also agree that the docs should mention this issue or at least the unimplmeneted functions should panic. Now towards supporting As background, I'd like to say what On the other hand, Thanks to the simplicity of the |
Thanks for the tip, we'll use a Send my regards to @jeehoonkang as my company once had been affiliated with his group, and the mentioned paper helped us a lot. |
Hi. I see this issue is still open, and wondered if I was missing something about the resolution. I don't know if Rust intends on having a different interpretation of sequential consistency, but when I refer to the Sequentially-consistent ordering section of https://en.cppreference.com/w/cpp/atomic/memory_order I see there is a code snippet which does a very similar sequence of changes to this bug report and it claims you only need to have the loads and stores ordered sequentially to avoid UB (and data-races). This seems inconsistent with the merged tests which appear to require the SeqCst store and load calls do not guarantee global sequencing. |
I don't know whether this issue should have been closed with #220. |
Well, it's still reproducible, so not closed as fixed either way. Possibly rejected if there is a different memory model being suggested. (again, only if I am understanding the promises of Sequential Consistency correctly) |
Rust uses the C++ memory model. |
Hey! I have two threads. First stores 1 to x and load y, second stores 1 to y and load x. But assert broke with message
thread 'main' panicked at 'x = 0, y = 0', src/main.rs:23:9
Why it possible with the SeqCst ordering?
The text was updated successfully, but these errors were encountered: