GATE / CS ARCHIVE

SIMILAR QUESTIONS / OPERATING SYSTEMS

Balance completed semaphore wait and signal operations

2 questions solved the same way, newest first. Back to Operating Systems

How these are solved

For a counting semaphore, apply the net effect of explicitly completed P and V operations to its starting value. Completion wording matters: this excludes problems asking whether pending operations can block.

1 mark · MCQ
Report issue

Asked again GATE 1992, Q2(x) (different numbers)

Net semaphore updates

Synchronization & Concurrency

Question 1.31, GATE 1998: A counting semaphore starts at 10. Six completed P(wait) and four completed V(signal) operations occur. Find the final value among 0, 8, 10, 12.
Tap to enlarge
Your answer
Answer & solution

Answer: B: 8 (no official key was published)

Each completed wait consumes one available unit, decreasing the count by 1. Each signal adds one unit. Thus the net change is−6+4=−2, and the final count is 10−2=8. Because all six waits are stated to complete and the initial count is sufficient even before signals, no blocking ambiguity affects this arithmetic. Hence B; counting only the signals would incorrectly increase the initial value.

Original paper, page 3

Report issue

Asked again GATE 1998, Q1.31 (different numbers)

Counting completed semaphore operations

Synchronization & Concurrency

Question 2(x), GATE 1992: A counting semaphore starts at 7. Twenty P and fifteen V operations complete. What is its final value?
Question 2(x), GATE 1992: A counting semaphore starts at 7. Twenty P and fifteen V operations complete. What is its final value?
Tap to enlarge
Select all that apply
Answer & solution

Answer: B: 2 (no official key was published)

Each completed P consumes one permit, decreasing the value by one; each V adds one. The net change is −20+15=−5, so the final value is 7−5=2. The word completed matters: blocked, uncompleted waits cannot simply be counted as successful acquisitions in a nonnegative semaphore convention. The stated totals permit an interleaving with enough signals before later waits, so no contradiction is implied by having twenty waits after an initial value of only seven.

Original paper, page 3