Skip to content

Commit

Permalink
fix test_weak_count_locked for Miri
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed May 11, 2020
1 parent c66d02e commit 7bea58e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/liballoc/sync/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ fn test_weak_count_locked() {
let mut a = Arc::new(atomic::AtomicBool::new(false));
let a2 = a.clone();
let t = thread::spawn(move || {
for _i in 0..1000000 {
// Miri is too slow
let count = if cfg!(miri) { 1000 } else { 1000000 };
for _i in 0..count {
Arc::get_mut(&mut a);
}
a.store(true, SeqCst);
Expand All @@ -349,6 +351,8 @@ fn test_weak_count_locked() {
while !a2.load(SeqCst) {
let n = Arc::weak_count(&a2);
assert!(n < 2, "bad weak count: {}", n);
#[cfg(miri)] // Miri's scheduler does not guarantee liveness, and thus needs this hint.
atomic::spin_loop_hint();
}
t.join().unwrap();
}
Expand Down

0 comments on commit 7bea58e

Please sign in to comment.