| 2 | use std::thread; |
| 3 | |
| 4 | fn std_correct() { |
| 5 | use std::sync::{Condvar, Mutex}; |
| 6 | |
| 7 | let pair1 = Arc::new((Mutex::new(false), Condvar::new())); |
| 8 | let pair2 = pair1.clone(); |
| 9 | |
| 10 | let th1 = thread::spawn(move || { |
| 11 | let (lock, cvar) = &*pair1; |
| 12 | let mut started = lock.lock().unwrap(); |
| 13 | while !*started { |
| 14 | started = cvar.wait(started).unwrap(); |
| 15 | } |
| 16 | }); |
| 17 | |
| 18 | let th2 = thread::spawn(move || { |
| 19 | let (lock, cvar) = &*pair2; |
| 20 | let mut started = lock.lock().unwrap(); |
| 21 | *started = true; |
| 22 | cvar.notify_one(); |
| 23 | }); |
| 24 | |
| 25 | th1.join().unwrap(); |
| 26 | th2.join().unwrap(); |
| 27 | } |
| 28 | |
| 29 | fn std_deadlock_wait() { |
| 30 | use std::sync::{Condvar, Mutex}; |