Skip to content

Commit 14e03dc

Browse files
committed
use strong_count and merge
1 parent 5c00501 commit 14e03dc

2 files changed

Lines changed: 26 additions & 62 deletions

File tree

tests/drop.rs

Lines changed: 0 additions & 62 deletions
This file was deleted.

tests/scope_local.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{
22
sync::Arc,
33
thread,
4+
panic,
45
};
56

67
use ctor::ctor;
@@ -57,6 +58,31 @@ fn shared() {
5758
}
5859

5960
assert_eq!(Arc::strong_count(&SHARED), 1);
61+
62+
let handles: Vec<_> = (0..9)
63+
.map(|_| {
64+
thread::spawn(move || {
65+
let mut scope = Scope::new();
66+
*SHARED.scope_mut(&mut scope) = SHARED.clone();
67+
assert!(Arc::strong_count(&SHARED) >= 2);
68+
})
69+
})
70+
.collect();
71+
72+
for h in handles {
73+
h.join().unwrap();
74+
}
75+
76+
assert_eq!(Arc::strong_count(&SHARED), 1);
77+
78+
let panic = panic::catch_unwind(|| {
79+
let mut scope = Scope::new();
80+
*SHARED.scope_mut(&mut scope) = SHARED.clone();
81+
panic!("panic");
82+
});
83+
assert!(panic.is_err());
84+
85+
assert_eq!(Arc::strong_count(&SHARED), 1);
6086
}
6187

6288
#[test]

0 commit comments

Comments
 (0)