Signaling and Event Notification
You'll learn how semaphores initialized to zero enable processes to coordinate their execution order through signaling.
The Core Idea
Sometimes you don't need mutual exclusion—you need synchronization: one process must wait until another process completes a specific task before proceeding. A semaphore initialized to 0 (not 1) becomes a powerful signaling mechanism for exactly this purpose.
Think of it like a relay race: the second runner can't start until the first runner hands off the baton. The baton handoff is the "signal."
How It Works
When a semaphore is initialized to 0:
- Process A performs
wait()on the semaphore → immediately blocks (because the value is 0) - Process B does its work, then calls
signal()→ increments the semaphore to 1 - Process A now unblocks and continues execution
This enforces ordering: A waits for B's signal that an event has occurred.
Example Scenario
Imagine a parent process that must wait for its child to finish initialization:
Parent: Child:
[initialize resources]
wait(ready) <---blocks signal(ready) <---signals completion
[use resources]
The semaphore ready starts at 0. The parent blocks on wait(ready) until the child completes initialization and calls signal(ready). This guarantees the parent doesn't proceed prematurely.
Why Not Use a Lock?
Locks protect shared data. Semaphores initialized to 0 coordinate timing—they don't guard a critical section, they enforce "B must happen before A."
Key Takeaway: A semaphore initialized to 0 acts as a signaling mechanism, allowing one process to notify another that an event has occurred and it's safe to proceed—enforcing execution order rather than mutual exclusion.