In embedded Rust, sharing data between the main thread and interrupt handlers requires careful consideration to ensure memory safety and avoid data races, particularly in single-core systems like Cortex-M. This document summarizes three common patterns—static Atomic<T>
, static Option<T>
, and Mutex<RefCell<Option<T>>>
—comparing their use cases, safety, and complexity, and evaluates whether the "move to context" trick applies.
Pattern | Data Types | Requires unsafe |
Synchronization | Overhead | Use Case | Move to Context Trick |
---|---|---|---|---|---|---|
static Atomic |
Primitives (bool , u32 ) |
No | Atomic op |