#![no_main] #![cfg_attr(target_os = "none", no_std)] use core::sync::atomic::{AtomicU32, Ordering}; struct Hydrogen { available: u32, bonded: u32, } rt::mutex!( H, Hydrogen, Hydrogen { available: 0, bonded: 0 } ); rt::condvar!(HREADY); rt::condvar!(HDONE); fn hydrogen() { let mut g = H.lock(); g.available += 1; HREADY.signal(); HDONE.wait_while(&g, |g| g.bonded == 0); g.bonded -= 1; } fn oxygen() { let mut g = H.lock(); HREADY.wait_while(&g, |g| g.available < 2); make_water(); g.available -= 2; g.bonded += 2; g.unlock(); HDONE.signal(); HDONE.signal(); } include!("water.rs");