Problem Statement
Master all synchronization primitives in Go's sync package for building thread-safe applications.
sync.Mutex vs sync.RWMutex
sync.Once
sync.WaitGroup
sync.Cond
sync/atomic
sync.Map
Key Interview Questions
- Q: When sync.Map over regular map+mutex?
A: Write-once read-many, or disjoint key sets per goroutine. - Q: Cost of atomic vs mutex?
A: Atomics are hardware instructions (~5-10ns), mutex involves OS calls (~30-50ns). - Q: Is it safe to copy a sync.Mutex?
A: NO! It copies lock state, causing deadlocks.