Interview prompt
Explain synchronization makes shared state predictable to an engineer who understands the surrounding system but has not used this technique. Walk from its contract to a concrete operation, then discuss where it fails or becomes expensive.
A strong answer
Concurrency means operations overlap in time; it does not require multiple CPU cores. When concurrent operations access shared mutable state, their interleaving can violate assumptions such as “read, increment, write happens atomically.” Synchronization establishes which transitions are allowed and who can observe them.
A mutex can protect a critical section so only one thread updates an invariant at a time. A condition variable lets a thread sleep until a predicate may have changed; the predicate must be checked in a loop after waking. Semaphores represent a count of available permits or events.
A complete answer also calls out the assumptions that control correctness. Locks prevent some races but can create deadlocks when threads acquire them in conflicting orders. Holding a lock during slow I/O can stall unrelated work. Atomics are useful for narrow state transitions but do not automatically make a multi-field invariant safe.
Close by describing one representative test or measurement. Two workers each need locks A and B. Describe a global lock-order rule that removes circular wait, and explain why merely adding timeouts changes rather than proves correctness.
Follow-up questions
Answer the follow-ups in the frontmatter. Use the linked article for the concept and the trace to make the explanation concrete.