After constructing the state diagram Does it solve the mutua
After constructing the state diagram:
Does it solve the mutual exclusion problem?
Consider the following algorithm for solving the MEP problem seen in class (assignment is assumed atomic for this exercise): global int np, nq =0; thread P: {while (true) {//non-critical section np = nq + 1; await nq == 0 or npSolution
Problem arises in a situation where there are process switches between p1/p2(or q1/q2), and
a particular process has copied old value of np (or nq) just before resets to 0 on q5 (or p5).
Taking Example:
1) Initially np=0 nq=0
2) P executes once cycle (p1 to P4) and now np= 1
3)Q executes q1, and temp(Q)=1
4)P executes p5, and np == 0
5)P executes p1, and temp(P) == 0
6)Q executes q2,and nq == 2
7)Q executes q3 because np==0
8)P executes p2, and np == 1
9)P executes p3 because np!=nq
Both P and Q are in critical section now
