Skip to content

Commit 7bea58e

Browse files
committed
fix test_weak_count_locked for Miri
1 parent c66d02e commit 7bea58e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/liballoc/sync/tests.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,9 @@ fn test_weak_count_locked() {
340340
let mut a = Arc::new(atomic::AtomicBool::new(false));
341341
let a2 = a.clone();
342342
let t = thread::spawn(move || {
343-
for _i in 0..1000000 {
343+
// Miri is too slow
344+
let count = if cfg!(miri) { 1000 } else { 1000000 };
345+
for _i in 0..count {
344346
Arc::get_mut(&mut a);
345347
}
346348
a.store(true, SeqCst);
@@ -349,6 +351,8 @@ fn test_weak_count_locked() {
349351
while !a2.load(SeqCst) {
350352
let n = Arc::weak_count(&a2);
351353
assert!(n < 2, "bad weak count: {}", n);
354+
#[cfg(miri)] // Miri's scheduler does not guarantee liveness, and thus needs this hint.
355+
atomic::spin_loop_hint();
352356
}
353357
t.join().unwrap();
354358
}

0 commit comments

Comments
 (0)