Skip to content

Commit 9a0aa41

Browse files
committed
failing RMWs are just reads
1 parent 5eeb272 commit 9a0aa41

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Diff for: src/tools/miri/tests/pass/concurrency/data_race.rs

+17
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,22 @@ fn mixed_size_read_read() {
166166
});
167167
}
168168

169+
fn failing_rmw_is_read() {
170+
let a = AtomicUsize::new(0);
171+
thread::scope(|s| {
172+
s.spawn(|| unsafe {
173+
// Non-atomic read.
174+
let _val = *(&a as *const AtomicUsize).cast::<usize>();
175+
});
176+
177+
s.spawn(|| {
178+
// RMW that will fail.
179+
// This is not considered a write, so there is no data race here.
180+
a.compare_exchange(1, 2, Ordering::SeqCst, Ordering::SeqCst).unwrap_err();
181+
});
182+
});
183+
}
184+
169185
pub fn main() {
170186
test_fence_sync();
171187
test_multiple_reads();
@@ -174,4 +190,5 @@ pub fn main() {
174190
test_read_read_race1();
175191
test_read_read_race2();
176192
mixed_size_read_read();
193+
failing_rmw_is_read();
177194
}

0 commit comments

Comments
 (0)