A semaphore count of negative n means (S = −n) that the queue contains…
2009
A semaphore count of negative n means (S = −n) that the queue contains ________ waiting processes.
Answer: B. n — A counting semaphore S records the running difference between signal() (V) calls and wait() (P) calls, and its sign has a fixed meaning: If S ≥ 0, S equals…
- A.
n + 1
- B.
n
- C.
n - 1
- D.
0
Attempted by 171 students.
Show answer & explanation
Correct answer: B
A counting semaphore S records the running difference between signal() (V) calls and wait() (P) calls, and its sign has a fixed meaning:
If S ≥ 0, S equals the number of resource units currently free; no process is waiting.
If S < 0, every wait() call that could not find a free unit is blocked; the magnitude |S| equals exactly the number of processes currently queued in the semaphore's wait queue.
The question gives S = −n, a negative value of magnitude n. Applying the rule directly, the wait queue must hold |S| = |−n| = n processes — no more and no fewer.
This can be checked independently by tracing the P/V accounting from S = 0:
Start with S = 0 and an empty queue (no free unit, no waiters).
n processes each execute wait(); since no unit is free, every call decrements S by one and blocks its caller, driving S from 0 down to −n and placing all n callers in the queue.
At this point S = −n exactly as given, and the queue holds precisely those n blocked processes, matching the rule above.
If n signal() calls are now issued, each increments S by one and releases one waiting process; after n signals S returns to 0 and the queue empties — confirming it held exactly n processes.
So a semaphore count of S = −n means the wait queue contains n waiting processes.