Sync is Rust’s marker trait for values that can be safely shared through references across threads. The compiler derives it automatically when appropriate; application code typically combines Arc, Mutex, or RwLock rather than implementing it directly. section 6.5
Use the trait distinction to interpret compiler errors and choose synchronization primitives:
- Send covers moving ownership between threads; Sync covers sharing references to the same value. section 6.5
- Use Arc when shared ownership must cross threads, then add AtomicI32, Mutex, or RwLock according to the mutation pattern. section 6.5
Sharing an atomic counter
A lazily initialized static AtomicI32 can be shared safely, and each test can update it with fetch_add and explicit ordering.
