Rust threads and message passing (mpsc) emphasize safe sharing—Send and Sync traits mark types safe to move across threads. Data races are compile-time errors with proper borrowing.
Threads preview
use std::thread;
let handle = thread::spawn(|| { 1 + 1 });
Important interview questions and answers
- Q: Rust vs Go concurrency?
A: Go uses goroutines and channels; Rust uses OS threads, async, and strict ownership for safety.
Self-check
- What does Send mean?
- Can Rc be shared across threads safely?
Tip: Prefer message passing (mpsc) over shared mutable state; use Arc<Mutex<T>> when sharing is required.
Interview prep
- Send vs Sync?
Send: safe to transfer ownership to another thread.Sync: safe to share references across threads.