Synchronization & Concurrency
![Question 73, GATE 1997: Three processes use a shared resource R mutually exclusively and nonpreemptively. Each has a unique fixed priority in {1,2,3}, with 3 highest. Shared state: semaphore mutex=1; semaphores proceed[1..3]=0; Boolean R_requested[1..3]=false; Boolean busy=false. Each process repeats request_R(my_priority); P(proceed[my_priority]); use R; release_R(my_priority). The supplied request_R(p) performs P(mutex); if busy then R_requested[p]:=true else begin V(proceed[p]); busy:=true end; V(mutex). Give release_R so each allocation goes to the highest-priority current requester. The shared-data declaration is printed as process[3] in the reproduction, while uses consistently say proceed; normalize that apparent naming typo explicitly.](../../assets/questions/CS-1997-Q93-1.webp)
![Question 73, GATE 1997: Three processes use a shared resource R mutually exclusively and nonpreemptively. Each has a unique fixed priority in {1,2,3}, with 3 highest. Shared state: semaphore mutex=1; semaphores proceed[1..3]=0; Boolean R_requested[1..3]=false; Boolean busy=false. Each process repeats request_R(my_priority); P(proceed[my_priority]); use R; release_R(my_priority). The supplied request_R(p) performs P(mutex); if busy then R_requested[p]:=true else begin V(proceed[p]); busy:=true end; V(mutex). Give release_R so each allocation goes to the highest-priority current requester. The shared-data declaration is printed as process[3] in the reproduction, while uses consistently say proceed; normalize that apparent naming typo explicitly.](../../assets/questions/CS-1997-Q93-2.webp)
Answer & solution
Answer: Under mutex, select the highest set request flag, clear it and signal that process while retaining busy=true; set busy=false only if no process waits. (no official key was published)
The release operation must inspect request flags and either transfer ownership or mark the resource free as one atomic critical section. Otherwise a new requester could take R between checking the flags and waking a waiting process. This code uses the same proceed array as the process and request routines; the source's isolated process spelling is treated as a declaration typo.
procedure release_R(my_priority):
P(mutex)
chosen := 0
for p := 3 downto 1 do
if R_requested[p] then
chosen := p
break
if chosen = 0 then
busy := false
else
R_requested[chosen] := false
busy := true
V(proceed[chosen])
V(mutex)The parameter my_priority identifies the releasing owner but is not needed to select the next one. Preconditions are that only the current owner calls release_R, each process has at most one outstanding request, and P/V have standard semaphore semantics. The no-waiter branch does not signal a semaphore: the next arriving requester will signal its own proceed entry in request_R before doing P on it.
Why keep busy true during handoff? A signaled process may not run immediately. The resource is nevertheless reserved for it; setting busy false would let a newcomer receive a second grant. Clearing the chosen flag prevents a later release from treating the same already-granted request as still waiting. Lower-priority flags remain set, preserving their requests.
Since priorities are unique and the loop scans 3,2,1, it chooses the highest pending priority at the moment of allocation. A higher-priority process arriving after that atomic choice must wait: the resource is nonpreemptive, so priority does not revoke an existing grant. At most one grant exists at a time, maintaining mutual exclusion. This scheme can starve a low-priority requester if higher-priority requests keep arriving; starvation freedom was not requested and does not follow from strict priority allocation.