#![no_main]
#![no_std]
use async_embedded::{task, unsync::Mutex};
use cortex_m_rt::entry;
use cortex_m_semihosting::hprintln;
use panic_semihosting as _; use stm32f1xx_hal as _;
#[entry]
fn main() -> ! {
static mut X: Mutex<u32> = Mutex::new(0);
let mut lock = X.try_lock().unwrap();
let a = async {
hprintln!("Task `a` will write now.").ok();
*lock = 42;
drop(lock);
hprintln!("Task `a` has dropped the lock.").ok();
loop {
hprintln!("Task `a` will yield now.").ok();
task::r#yield().await;
}
};
task::spawn(a);
let b = async {
hprintln!("Task `b` will asynchronously lock the mutex now.").ok();
let lock = X.lock().await;
hprintln!("Task `b`: *lock = {:?}", *lock).ok();
hprintln!("Task `b` will not yield again.").ok();
loop {}
};
task::block_on(b)
}