Processes need to acquire a resource or enter a critical section atomically, without race conditions. We need an operation that decrements the semaphore and blocks if the resource isn’t available.
The wait() operation (P operation) decrements the semaphore value atomically. If the result is negative, the process blocks and waits.
- Atomically decrement semaphore value: S = S - 1
- If S ≥ 0 after decrement: process continues (acquired resource)
- If S < 0 after decrement: process blocks and is added to wait queue
- Process sleeps until another process calls signal()
- Must be atomic (no interruption during execution)
- Can cause blocking (process sleeps)
- Implemented in kernel (for system semaphores)
- Also called P (prolagen = to test) or down operation
- Built from: Semaphore
- Builds into: Binary Semaphore, Counting Semaphore
- Related: Signal Operation, Critical Section
- Contrasts with: Signal Operation (decrement vs increment)
- Busy-waiting implementation wastes CPU (better to sleep)
- Must be atomic — can’t be interrupted mid-execution
- Forgetting to call wait() causes race conditions