struct S { v: i32 } fn main() { let n_container = std::sync::Arc::new(std::sync::Mutex::new(S{v: 0})); let main_sync = std::sync::Arc::new(std::sync::Condvar::new()); let th_sync = main_sync.clone(); 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(mut my_n) = lock_result { while my_n.v == 0 { my_n = th_sync.wait(my_n).unwrap(); } 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(999)); lock_result = n1.lock(); if let std::sync::LockResult::Ok(mut main_n) = lock_result { println!("Main thread, here!"); main_n.v = 6; main_sync.notify_one(); println!("My new n value is {}", main_n.v); } h.join(); }