Two concurrent processes P1 and P2 want to use two resources R1 and R2 in a…

PYQ GATE 2001

Two concurrent processes P1 and P2 want to use two resources R1 and R2 in a mutually exclusive manner. Initially, R1 and R2 are free. The programs executed by the two processes are given below.

Program for P1:

S1: While (R1 is busy) do no-op;
S2: Set R1 ← busy;
S3: While (R2 is busy) do no-op;
S4: Set R2 ← busy;
S5: Use R1 and R2;
S6: Set R1 ← free;
S7: Set R2 ← free;

Program for P2:

Q1: While (R1 is busy) do no-op;
Q2: Set R1 ← busy;
Q3: While (R1 is busy) do no-op;
Q4: Set R1 ← busy;
Q5: Use R1 and R2;
Q6: Set R2 ← free;
Q7: Set R1 ← free;

(a) Is mutual exclusion guaranteed for R1 and R2? If not, show a possible interleaving of the statements of P1 and P2 such that mutual exclusion is violated (i.e., both P1 and P2 use R1 or R2 at the same time).

(b) Can deadlock occur in the above program? If yes, show a possible interleaving of the statements of P1 and P2 leading to deadlock.

(c) Exchange the statements Q1 and Q3 and statements Q2 and Q4. Is mutual exclusion guaranteed now? Can deadlock occur?

Sign up free to check your answer

Sign up free

Explore the full course: Operating System

Loading lesson…