()
| 18 | } |
| 19 | |
| 20 | fn two_closures() { |
| 21 | let lock_a1 = Arc::new(Mutex::new(1)); |
| 22 | let lock_a2 = lock_a1.clone(); |
| 23 | let lock_b1 = Arc::new(Mutex::new(true)); |
| 24 | let lock_b2 = lock_b1.clone(); |
| 25 | let th1 = thread::spawn(move || { |
| 26 | let _b = lock_b1.lock().unwrap(); |
| 27 | let _a = lock_a1.lock().unwrap(); |
| 28 | }); |
| 29 | let th2 = thread::spawn(move || { |
| 30 | let _a = lock_a2.lock().unwrap(); |
| 31 | let _b = lock_b2.lock().unwrap(); |
| 32 | }); |
| 33 | th1.join().unwrap(); |
| 34 | th2.join().unwrap(); |
| 35 | } |
| 36 | |
| 37 | fn main() { |
| 38 | one_closure_one_caller(); |