File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff 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+
200216pub 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}
You can’t perform that action at this time.
0 commit comments