https://japaric.github.io/rustfest-2017-09-30
Jorge Aparicio - @japaric - jorapa-7@student.ltu.se
Per Lindgren - Per.Lindgren@ltu.se
Lulea University of Technology
I/O with the world
Cheap. Simple. Low power. Full control.
let mut task1 = || {
loop {
let byte = await!(serial.gread()).unwrap();
await!(serial.gwrite(byte)).unwrap();
}
};
let mut on = false;
let mut task2 = || {
loop {
on = !on;
if on {
LED.on();
} else {
LED.off();
}
await!(timer.gwait());
}
};
Scenario: You need to execute two periodic tasks concurrently.
Can these timing constrains be satisfied using cooperative multitasking?
In general, no. We need task prioritization, which requires preemption.
use cortex_m::interrupt;
fn main() {
loop {
interrupt::free(|_|
unsafe { DATA.modify(); }
);
}
}
interrupt!(EXTI0, handler);
fn handler() {
unsafe { DATA.modify() }
}
Now this is memory safe.
Not all contexts need to lock the data.
Beyond locking.
Concurrent Reactive Objects (CRO)
(if there's time)
(inb4 "Where are my threads?!")