#![no_main] #![cfg_attr(target_os = "none", no_std)] use core::sync::atomic::{AtomicBool, Ordering}; rt::mutex!(MUTEX, u32, 0); rt::condvar!(COND); static FLAG: AtomicBool = AtomicBool::new(false); const ITERATIONS: i32 = 1000; fn signaler() { rt::task::drop_privilege(); loop { let _g = MUTEX.lock(); FLAG.store(true, Ordering::Relaxed); COND.signal(); } } fn incrementer() { rt::task::drop_privilege(); let mut g = MUTEX.lock(); for _ in 0..ITERATIONS { COND.wait_while(&g, |_| !FLAG.load(Ordering::Relaxed)); *g += 1; FLAG.store(false, Ordering::Relaxed); } rt::trap(); } fn timeout() { rt::task::sleep(1000); panic!("timed out"); } const STACK_SIZE: usize = rt::stack::MIN * 4; rt::task!(signaler, rt::stack::MIN, 2); rt::task!(incrementer, rt::stack::MIN, 1); rt::task!(incrementer, rt::stack::MIN, 1); rt::task!(timeout, STACK_SIZE, 0);