Synchronization coordinates concurrent operations so shared state changes occur in a consistent order. It prevents race conditions by controlling access, blocking competing operations when necessary. section 6.5.2 section 11.0
Choose the mechanism according to the coordination problem:
- Use a lock, or mutex, to protect a critical section; acquire it before changing shared data and release it afterward. section 6.5.2
- Use a semaphore to limit concurrent access to a resource such as a database connection pool. section 11.0
- Use events and conditions to notify tasks when data or another required state becomes available. section 11.0
Protecting a shared counter
Two processes incrementing the same integer can produce an incorrect result. Locking the increment makes one process wait while the other reads, updates, and releases the shared value; a context manager expresses the same acquire-and-release pattern. section 6.5.2
A process-level diagram makes the waiting behavior visible: one process holds the lock while another is blocked from reading shared data. section 6.5.2









