Question: Question 1 : Mutual Exclusion [ 2 0 marks ] Consider the following program intended to solve the mutual exclusion problem for the case of

Question 1: Mutual Exclusion [20 marks]
Consider the following program intended to solve the mutual exclusion problem for the case of two processes.
\[
\begin{array}{l}
\text { int }\mathrm{cp}=0\\
\text { int }\mathrm{cq}=0
\end{array}
\]
```
Process P
while( true ){
P1: non-critical-section;
P2a: if( cq ==-1){
P2b: }\quadcp=-1\mathrm{ ;
P2c: } else { cp =1; }
P3: while(cp == cq){}
P4: critical-section;
P5: cp =0;
}
end P;
```
```
Process Q
while( true ){
Q1: non-critical-section;
Q2a: if( cp ==-1){
Q2b: \q =1;
Q2c: } else { cq =-1; }
Q3: while(cq ==-cp){}
Q4: critical-section;
Q5: \q =0;
}
end Q;
```
Assuming that each line is atomic, answer the following questions (and pay careful attention to the signs of quantities):
(i) Find an execution of this algorithm that demonstrates that mutual exclusion is not upheld.
(ii) Now assume that the statements (P2a,P2b,P2c) are executed as a single atomic instruction and the same for (Q2a,Q2b,Q2c)(see next page). Does the program now uphold mutual exclusion? Provide a proof. ```
Process P
while( true ){
P1: non-critical-section;
P2: if( cq ==-1){cp =-1;} else {cp =1; }
P3: while(cp == cq){}
P4: critical-section;
P5: cp =0;
}
end P;
```
```
Process Q
while( true ){
non-critical-section;
if( cp ==-1){cq =1;} else { cq =-1; }
while(cq ==-cp){}
critical-section;
cq =0;
}
end Q;
```
Question 1 : Mutual Exclusion [ 2 0 marks ]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!