<skill_overview> Write correct, deadlock-free concurrent Rust code
Spawning threads or tasks Sharing state across threads Using channels for message passing Writing async/await code
The Rust Book - Concurrency The Rust Book - Async/Await
</skill_overview> <message_passing>
Prefer channels to avoid shared mutable state Move ownership through channels to enforce safety
use std::sync::mpsc;
let (tx, rx) = mpsc::channel(); tx.send(42).unwrap(); let value = rx.recv().unwrap();
</message_passing> <shared_state>
Use Arc<Mutex<T>> or Arc<RwLock<T>> for shared mutable state Keep lock scopes minimal and consistent Handle poison errors explicitly
</shared_state> <send_sync>
Use types that implement Send and Sync across threads Avoid Rc and RefCell in multi-threaded code
</send_sync> <async_guidelines>
Use async/await for I/O-bound work Do not block inside async functions Async code still needs an executor to run
</async_guidelines>
Lock in a consistent order Drop guards before calling into other code
<anti_patterns> Using Rc<T> across threads Holding a lock across long operations Blocking I/O inside async code </anti_patterns>