Overview of Embedded Concurrency Frameworks
masterBeyond manual Mutex<RefCell<Option<T>>> patterns, several frameworks provide more efficient or ergonomic concurrency models:
RTIC (Real Time Interrupt-driven Concurrency)
RTIC uses static priorities to manage resource access. It tracks access to static mut variables (resources) at compile time, ensuring safety without the runtime overhead of RefCell or constant critical sections. It also supports:
asynctasks via an asynchronous executor.- Message passing.
- Scheduled tasks.
Embassy
Embassy is an ecosystem focused on Rust's async/await syntax. It provides:
- An
asynchronous executorsupporting most MCU architectures. - A
Time library. - Various HAL libraries.
embassy-syncfor synchronization primitives.
RTOS (Real-Time Operating Systems)
Traditional models like FreeRTOS or ChibiOS use threads and multitasking:
- Cooperative multitasking: Threads yield control.
- Preemptive multitasking: The OS swaps threads based on timers or interrupts.
Multi-core Concurrency
On multi-core systems, single-core critical sections (like cortex_m::interrupt::Mutex) are insufficient. You must use synchronization primitives designed for SMP (Symmetric Multi-Processing), which typically rely on atomic instructions to maintain atomicity across all cores.