GATE / CS ARCHIVE

GATE CSE 1992 / QUESTION 2(x)

Counting completed semaphore operations

Operating Systems · Synchronization & Concurrency · Full GATE CSE 1992 paper

GATE 1992, Q2(x) MSQ
Report issue

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