#![no_main] #![cfg_attr(target_os = "none", no_std)] use core::sync::atomic::{AtomicUsize, Ordering}; rt::queue!(QUEUE, u32, 10); fn pusher(mut i: u32) { rt::task::drop_privilege(); loop { QUEUE.push(i); i += 1; } } const NPUSHERS: usize = 2; const TASK_INC: u32 = 0x1000000; static NUM_POPPED: AtomicUsize = AtomicUsize::new(0); fn popper() { rt::task::drop_privilege(); let mut max_elems = [0u32; NPUSHERS]; loop { let x = QUEUE.peek(); let y = QUEUE.pop(); assert!(x == y, "peeked and popped value don't match"); NUM_POPPED.fetch_add(1, Ordering::Relaxed); let task = x / TASK_INC; let elem = x % TASK_INC; if let Some(max_elem) = max_elems.get_mut(task as usize) { assert!( elem >= *max_elem, "queue elements were received out of order" ); *max_elem = elem; } } } fn timeout() { rt::task::drop_privilege(); rt::task::sleep(1000); rt::trap(); } const STACK_SIZE: usize = rt::stack::MIN * 8; rt::task!(pusher(0), STACK_SIZE, 1); rt::task!(pusher(TASK_INC), STACK_SIZE, 1); rt::task!(popper, STACK_SIZE, 1); rt::task!(timeout, rt::stack::MIN, 0);