+
+ // shared state
+ let counter = sync::Arc::new(sync::Mutex::new(0));
+ let mut threads = vec![];
+ for _ in 0..10 {
+ let tc = sync::Arc::clone(&counter);
+ threads.push(thread::spawn(move || {
+ *tc.lock().unwrap() += 1;
+ }));
+ }
+
+ for t in threads {
+ t.join().unwrap();
+ }
+
+ println!("counter: {}", *counter.lock().unwrap());