Similar questions 1 more → · asked again: GATE 1998, Q1.31
Synchronization & Concurrency


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.