diff options
Diffstat (limited to 'examples/basic.rs')
| -rw-r--r-- | examples/basic.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/examples/basic.rs b/examples/basic.rs index 4ff85f8..8842e16 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -7,12 +7,18 @@ const N: usize = 10; static DATA: Mutex<i32> = Mutex::new(0); fn main() { + let mut threads = Vec::new(); for _ in 0..N { - thread::spawn(move || { + let th = thread::spawn(move || { let key = ThreadKey::lock().unwrap(); let mut data = DATA.lock(key); *data += 1; }); + threads.push(th); + } + + for th in threads { + _ = th.join(); } let key = ThreadKey::lock().unwrap(); |
