Open
Description
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?
use loom::thread;
use loom::sync::atomic::{AtomicUsize, Ordering};
use loom::sync::Arc;
fn main() {
loom::model(|| {
let x = Arc::new(AtomicUsize::new(0));
let y = Arc::new(AtomicUsize::new(0));
let x1 = x.clone();
let y1 = y.clone();
let x2 = x.clone();
let y2 = y.clone();
let child_x = thread::spawn(move || {
x1.store(1, Ordering::SeqCst);
y1.load(Ordering::SeqCst)
});
let child_y = thread::spawn(move || {
y2.store(1, Ordering::SeqCst);
x2.load(Ordering::SeqCst)
});
let res_x = child_x.join().unwrap();
let res_y = child_y.join().unwrap();
assert!(!(res_x == 0 && res_y == 0), "x = {}, y = {}", res_x, res_y);
})
}
Metadata
Metadata
Assignees
Labels
No labels