use std::sync::{Mutex, Arc};
use std::thread;

fn main() {
    let counter = Arc::new(Mutex::new(0));
    let mut handles = vec![];

    for _ in 1..10 {
        let counter = counter.clone();
        let handle = thread::spawn(move || {
            let mut num = counter.lock().unwrap();

            *num += 1;
        });
        handles.push(handle);
    }

    for handle in handles {
        handle.join().unwrap();
    }

    println!("Result: {}", *counter.lock().unwrap());
}

use std::sync::Mutex;

fn main() {
    let m = Mutex::new(5);

    {
        let mut num = m.lock().unwrap();
        *num = 6;
    }

    println!("m = {:?}", m);
}

--- 
+++ 
@@ -1,12 +1,23 @@
-use std::sync::Mutex;
+use std::sync::{Mutex, Arc};
+use std::thread;
 
 fn main() {
-    let m = Mutex::new(5);
+    let counter = Arc::new(Mutex::new(0));
+    let mut handles = vec![];
 
-    {
-        let mut num = m.lock().unwrap();
-        *num = 6;
+    for _ in 1..10 {
+        let counter = counter.clone();
+        let handle = thread::spawn(move || {
+            let mut num = counter.lock().unwrap();
+
+            *num += 1;
+        });
+        handles.push(handle);
     }
 
-    println!("m = {:?}", m);
+    for handle in handles {
+        handle.join().unwrap();
+    }
+
+    println!("Result: {}", *counter.lock().unwrap());
 }
Use mutex with multiple threads and Arc
