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 lock_result; let thread_body = move || { for i in 1..10 { { let lock_result = n.lock(); if let std::sync::LockResult::Ok(my_n) = lock_result { println!("Count {}, n is {}", i, my_n.v); } else { println!("Lock failed???"); } } 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)); lock_result = n1.lock(); if let std::sync::LockResult::Ok(mut main_n) = lock_result { println!("Main thread, here!"); main_n.v = 6; println!("My new n value is {}", main_n.v); drop(main_n); } h.join(); }