Send Sync and Thread Safety
CONCEPTS:Rust Send and Sync
Question Variations
- "What is the difference between `Send` and `Sync`?"
- "Why is `Rc<T>` not `Send`?"
- "Why does `Arc<Mutex<T>>` work across threads?"
- "Should application code implement `Send` or `Sync` manually?"
Why This Is Asked
Rust’s concurrency guarantees come from ownership and its auto traits. This question checks whether you can explain what Send and Sync mean, understand why certain types are rejected across threads, and compose shared state safely.
Key Concepts
Sendpermits transferring ownership of a value to another thread.Syncpermits sharing&Tbetween threads safely.- Most ordinary owned data is automatically
SendandSyncwhen its fields are. Arc<Mutex<T>>is a common pattern for shared, mutable state across threads.
Question Variations
- “What is the difference between
SendandSync?” - “Why is
Rc<T>notSend?” - “Why does
Arc<Mutex<T>>work across threads?” - “Should application code implement
SendorSyncmanually?”