Skip to content

Commit 5a88938

Browse files
committed
Further clarificarion for atomic and UnsafeCell docs:
- UnsafeCell: mention the term "data race", and reference the data race definition - atomic: failing RMWs are just reads, reorder and reword docs
1 parent 0cf32db commit 5a88938

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/pass/concurrency/data_race.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,22 @@ fn mixed_size_read_read() {
197197
});
198198
}
199199

200+
fn failing_rmw_is_read() {
201+
let a = AtomicUsize::new(0);
202+
thread::scope(|s| {
203+
s.spawn(|| unsafe {
204+
// Non-atomic read.
205+
let _val = *(&a as *const AtomicUsize).cast::<usize>();
206+
});
207+
208+
s.spawn(|| {
209+
// RMW that will fail.
210+
// This is not considered a write, so there is no data race here.
211+
a.compare_exchange(1, 2, Ordering::SeqCst, Ordering::SeqCst).unwrap_err();
212+
});
213+
});
214+
}
215+
200216
pub fn main() {
201217
test_fence_sync();
202218
test_multiple_reads();
@@ -206,4 +222,5 @@ pub fn main() {
206222
test_read_read_race1();
207223
test_read_read_race2();
208224
mixed_size_read_read();
225+
failing_rmw_is_read();
209226
}

0 commit comments

Comments
 (0)