Two concurrent processes $P1$ and $P2$ want to use 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.
$$\begin{array}{|ll|ll|}\hline & \textbf{Program for P1:} && \textbf{Program for P2:} \\\hline \text{S1:} & \text{While ($R1$ is busy) do no-op;} & \text{Q1:} & \text{While ($R1$ is busy) do no-op;} \\ \text{S2:} & \text{Set $R1$ $\leftarrow$ busy;} & \text{Q2:} & \text{Set $R1$ $\leftarrow$ busy;} \\ \text{S3:} & \text{While ($R2$ is busy) do no-op;} & \text{Q3:} & \text{While ($R2$ is busy) do no-op;} \\ \text{S4:} & \text{Set $R2$ $\leftarrow$ busy;} & \text{Q4:} & \text{Set $R2$ $\leftarrow$ busy;} \\ \text{S5:} & \text{Use $R1$ and $R2$;} & \text{Q5:} & \text{Use $R1$ and $R2$;} \\ \text{S6:} & \text{Set $R1$ $\leftarrow$ free;} & \text{Q6:} & \text{Set $R2$ $\leftarrow$ free;} \\ \text{S7:} & \text{Set $R2$ $\leftarrow$ free;} & \text{Q7:} & \text{Set $R1$ $\leftarrow$ free;} \\\hline \end{array}$$
I didn't understand the last question.
Exchange the statements Q1 and Q3 and statements Q2 and Q4. Is mutual exclusion guaranteed now? Can deadlock occur?
what is the difference between these two?
While R1 is busy do no-op While (R1 is busy) do no-op
While R1 is busy do no-op
While (R1 is busy) do no-op
Please explain.
@Pratik Gawali
S4 will set R2 to busy. So how will the sequence ..., S4, Q7, Q1, Q2, Q3, Q4, ... be possible?
Also, since Deadlock is possible for this case, Mutual Exclusion has to be guaranteed right?
S1,Q1,Q2,Q3,S2,S3,Q4,Q5,Q6,S4,Q7,Q1,Q2,Q3,Q4,Q5,S5...
again when P2 executes these statements Q1,Q2,Q3,Q4 P2 will be stuck into the while loop. Because already P1 is set as R1 and R2 is busy.
64.3k questions
77.9k answers
244k comments
80.0k users