Question
Consider a non-negative counting semaphore . The operation decrements , and increments . During an execution, 20 operations and 12 operations are issued in some order. The largest initial value of for which at least one operation will remain blocked is _____.
Official answer and solution
- Official answer
- 7
- From
- Official GATE 2016 answer key
Solution
Find the maximum initial semaphore value that permits at least one operation to remain blocked in the worst-case order.
Let be the initial value of the counting semaphore ().
During execution, 20 and 12 operations are issued in some order. Each successful operation decrements by 1. Each operation either increments by 1 or unblocks one waiting process.
The total number of available resources across the entire execution is the initial value plus all increments from :
To maximize the number of blocked operations, consider an order where all 20 operations are issued before any operation:
- The first operations of succeed without blocking, leaving .
- The remaining operations of find and become blocked.
- Then the 12 operations are issued, unblocking at most 12 waiting operations.
- The number of operations that remain blocked is:
For at least one operation to remain blocked:
If , then operations block initially, and 12 operations unblock 12 of them, leaving exactly 1 operation blocked.
If , at most 12 operations block initially, and the 12 operations will unblock all of them, so no operation remains blocked.
Thus, the largest initial value of is 7.
7
Setting to get 8, which is the smallest value ensuring NO operations remain blocked, rather than the largest value where AT LEAST ONE remains blocked.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2016 Computer Science and Information Technology (CS) Session 2
- Question
- 59 of 65, printed as CS Q.49
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.