struct S { v: i32 } fn main() { let n_container = std::sync::Arc::new(std::sync::Mutex::new(S{v: 5})); let n = std::sync::Arc::clone(&n_container); let n1 = std::sync::Arc::clone(&n_container); let mut main_n; let thread_body = move || { for i in 1..10 { { let my_n = n.lock().unwrap(); println!("Count {}, n is {}", i, my_n.v); } std::thread::sleep(std::time::Duration::from_millis(100)); } }; let h = std::thread::spawn(thread_body); std::thread::sleep(std::time::Duration::from_millis(300)); main_n = n1.lock().unwrap(); println!("Main thread, here!"); main_n.v = 6; println!("My new n value is {}", main_n.v); drop(main_n); h.join().unwrap(); }