File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -618,3 +618,22 @@ fn test_arc_cyclic_two_refs() {
618
618
assert_eq ! ( Arc :: strong_count( & two_refs) , 3 ) ;
619
619
assert_eq ! ( Arc :: weak_count( & two_refs) , 2 ) ;
620
620
}
621
+
622
+ /// Test for Arc::drop bug (https://github.com/rust-lang/rust/issues/55005)
623
+ #[ test]
624
+ #[ cfg( miri) ] // relies on Stacked Borrows in Miri
625
+ fn arc_drop_dereferenceable_race ( ) {
626
+ // The bug seems to take up to 700 iterations to reproduce with most seeds (tested 0-9).
627
+ for _ in 0 ..750 {
628
+ let arc_1 = Arc :: new ( ( ) ) ;
629
+ let arc_2 = arc_1. clone ( ) ;
630
+ let thread = thread:: spawn ( || drop ( arc_2) ) ;
631
+ // Spin a bit; makes the race more likely to appear
632
+ let mut i = 0 ;
633
+ while i < 256 {
634
+ i += 1 ;
635
+ }
636
+ drop ( arc_1) ;
637
+ thread. join ( ) . unwrap ( ) ;
638
+ }
639
+ }
Original file line number Diff line number Diff line change @@ -329,3 +329,22 @@ fn test_scoped_threads_nll() {
329
329
let x = 42_u8 ;
330
330
foo ( & x) ;
331
331
}
332
+
333
+ // Regression test for https://github.com/rust-lang/rust/issues/98498.
334
+ #[ test]
335
+ #[ cfg( miri) ] // relies on Miri's data race detector
336
+ fn scope_join_race ( ) {
337
+ for _ in 0 ..100 {
338
+ let a_bool = AtomicBool :: new ( false ) ;
339
+
340
+ thread:: scope ( |s| {
341
+ for _ in 0 ..5 {
342
+ s. spawn ( || a_bool. load ( Ordering :: Relaxed ) ) ;
343
+ }
344
+
345
+ for _ in 0 ..5 {
346
+ s. spawn ( || a_bool. load ( Ordering :: Relaxed ) ) ;
347
+ }
348
+ } ) ;
349
+ }
350
+ }
You can’t perform that action at this time.
0 commit comments