Shared mutable state in Rust (2022) (draft.ryhl.io)
The article explains how to safely share and mutate data in Rust across threads using Arc for shared ownership and Mutex for synchronized access. It recommends wrapping Arc/Mutex inside a custom struct to keep locking implementation details out of your API. For async code, it warns against holding a std::sync::Mutex lock across an .await (which can cause deadlocks) and shows patterns like locking only in non-async helper methods, illustrated with a debouncer example. It also discusses how the compiler typically catches the unsafe “mutex guard across await” case and briefly compares std mutexes with async locks and alternative approaches like RwLock or arc-swap.
April 05, 2026 12:30
Source: Hacker News