Skip to content

Commit 8416713

Browse files
committed
Add test test_weak_count_locked
1 parent 49edaf1 commit 8416713

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/liballoc/arc.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,25 @@ mod tests {
15011501
assert!(Arc::ptr_eq(&five, &same_five));
15021502
assert!(!Arc::ptr_eq(&five, &other_five));
15031503
}
1504+
1505+
#[test]
1506+
#[cfg_attr(target_os = "emscripten", ignore)]
1507+
fn test_weak_count_locked() {
1508+
let mut a = Arc::new(atomic::AtomicBool::new(false));
1509+
let a2 = a.clone();
1510+
let t = thread::spawn(move || {
1511+
for _i in 0..1000000 {
1512+
Arc::get_mut(&mut a);
1513+
}
1514+
a.store(true, SeqCst);
1515+
});
1516+
1517+
while !a2.load(SeqCst) {
1518+
let n = Arc::weak_count(&a2);
1519+
assert!(n < 2, "bad weak count: {}", n);
1520+
}
1521+
t.join().unwrap();
1522+
}
15041523
}
15051524

15061525
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)