Threads, Send/Sync & Shared State
The core of any RPC service under real load. Threads, the two auto traits that make sharing sound, Arc<Mutex<T>> and its alternatives, atomics with honest memory ordering, and channels.
// lessons
- 01
Spawning & Joining Threads
Run work in parallel and collect every result deterministically.
- 02
Send & Sync
Say why Rc is not Send and Arc is, from the definition rather than from memory.
- 03
Arc<T>: Shared Ownership Across Threads
Share read-only state with N workers at the cost of one atomic.
- 04
Mutex, Guards & Poisoning
Mutate shared state safely, and keep the critical section short on purpose.
- 05
RwLock & Read-Heavy State
Choose RwLock over Mutex on evidence, and name the starvation risk you took.
- 06
Deadlocks & Lock Ordering
Reproduce a deadlock, then remove it with a global lock order.
- 07
Atomics & Memory Ordering
Use fetch_add and compare_exchange, and justify Relaxed vs Acquire/Release.
- 08
Channels & Backpressure
Wire a producer/consumer with mpsc and explain what a bounded channel buys.
Every exercise compiles and runs in the Forge sandbox — standard library only, no external crates.
