Skip to content

Commit

Permalink
failing RMWs are just reads
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Aug 12, 2024
1 parent 5eeb272 commit 9a0aa41
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/tools/miri/tests/pass/concurrency/data_race.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,22 @@ fn mixed_size_read_read() {
});
}

fn failing_rmw_is_read() {
let a = AtomicUsize::new(0);
thread::scope(|s| {
s.spawn(|| unsafe {
// Non-atomic read.
let _val = *(&a as *const AtomicUsize).cast::<usize>();
});

s.spawn(|| {
// RMW that will fail.
// This is not considered a write, so there is no data race here.
a.compare_exchange(1, 2, Ordering::SeqCst, Ordering::SeqCst).unwrap_err();
});
});
}

pub fn main() {
test_fence_sync();
test_multiple_reads();
Expand All @@ -174,4 +190,5 @@ pub fn main() {
test_read_read_race1();
test_read_read_race2();
mixed_size_read_read();
failing_rmw_is_read();
}

0 comments on commit 9a0aa41

Please sign in to comment.