diff options
| author | Jacques-Henri Jourdan <jacques-henri.jourdan@normalesup.org> | 2017-07-20 01:59:01 +0200 |
|---|---|---|
| committer | Jacques-Henri Jourdan <jacques-henri.jourdan@normalesup.org> | 2017-07-20 01:59:01 +0200 |
| commit | 8416713240e11e898872f5028f927997f3754696 (patch) | |
| tree | b1921fb9ed1c5afbfb85a920da7fbaef1fc2061b /src/liballoc | |
| parent | 49edaf14fd1ef0c190e67998ad299db67d19b739 (diff) | |
| download | rust-8416713240e11e898872f5028f927997f3754696.tar.gz rust-8416713240e11e898872f5028f927997f3754696.zip | |
Add test test_weak_count_locked
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/arc.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 0205f3f3553..85c7efb7ac5 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -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")] |
