The GATE Grind

GATE 2016 CS (CS2) – Question 59

Operating System · Concurrency and Synchronization · 2 marks · Numerical answer

A nonnegative counting semaphore S uses P (decrement, blocking if unavailable) and V (increment). During execution twenty P and twelve V operations are issued in some order. Find the largest initial S for which a P remains blocked.

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: 7.0 to 7.0

Explanation

After all V operations there are S₀+12 total permits for twenty P operations. To leave at least one blocked, require S₀+12<20. Thus S₀<8 and the largest nonnegative integer is 7. With eight initially, all twenty P operations can eventually complete.

More Concurrency and Synchronization questions

All Concurrency and Synchronization questions →