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.
S1:S2:S3:S4:S5:S6:S7:Program for P1:While (R1 is busy) do no-op;Set R1 ← busy;While (R2 is busy) do no-op;Set R2 ← busy;Use R1 and R2;Set R1 ← free;Set R2 ← free;Q1:Q2:Q3:Q4:Q5:Q6:Q7:Program for P2:While (R1 is busy) do no-op;Set R1 ← busy;While (R2 is busy) do no-op;Set R2 ← busy;Use R1 and R2;Set R2 ← free;Set R1 ← free;