Skip to content

Commit bad41d8

Browse files
committed
add a test for multiple threads share one scope
1 parent 5a2ba55 commit bad41d8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/scope_local.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,30 @@ fn shared() {
7171

7272
assert_eq!(Arc::strong_count(&SHARED), 1);
7373

74+
{
75+
let mut scope = Scope::new();
76+
*SHARED.scope_mut(&mut scope) = SHARED.clone();
77+
let scope = Arc::new(scope);
78+
79+
let handles: Vec<_> = (0..10)
80+
.map(|_| {
81+
let scope = scope.clone();
82+
thread::spawn(move || {
83+
unsafe { ActiveScope::set(&scope) };
84+
assert_eq!(Arc::strong_count(&SHARED), 2);
85+
assert_eq!(*SHARED, Arc::new("qwq".to_string()));
86+
ActiveScope::set_global();
87+
})
88+
})
89+
.collect();
90+
91+
for h in handles {
92+
h.join().unwrap();
93+
}
94+
}
95+
96+
assert_eq!(Arc::strong_count(&SHARED), 1);
97+
7498
let panic = panic::catch_unwind(|| {
7599
let mut scope = Scope::new();
76100
*SHARED.scope_mut(&mut scope) = SHARED.clone();

0 commit comments

Comments
 (0)