Skip to content

Commit

Permalink
Add test test_weak_count_locked
Browse files Browse the repository at this point in the history
  • Loading branch information
jhjourdan committed Jul 19, 2017
1 parent 49edaf1 commit 8416713
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,25 @@ mod tests {
assert!(Arc::ptr_eq(&five, &same_five));
assert!(!Arc::ptr_eq(&five, &other_five));
}

#[test]
#[cfg_attr(target_os = "emscripten", ignore)]
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 {
Arc::get_mut(&mut a);
}
a.store(true, SeqCst);
});

while !a2.load(SeqCst) {
let n = Arc::weak_count(&a2);
assert!(n < 2, "bad weak count: {}", n);
}
t.join().unwrap();
}
}

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

0 comments on commit 8416713

Please sign in to comment.