The model
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 concrete walk-through
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.
Costs and failure cases
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.
Check your understanding
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.