Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(a) Given the following solution for the critical section problem for two proces

ID: 3844601 • Letter: #

Question

(a) Given the following solution for the critical section problem for two processes (the code shown is for processes Pi), show why it does not satisfy the mutual exclusion requirement. Here, turn, flag[i[], and flag[j] are is shared variables, flag[i] and flag[j] are initialized to FALSE and turn initialized to i. do {flag[i] true; turn = i; while (flag[j] && turn ==j); Critical section flag[i] = FALSE; Remainder section} (b) What happens if flag[i] and flag[j] are set to TRUE in the above code?

Explanation / Answer

a)Since variable turn is initialized to be i rather than j (turn=i) in Pi. So obviously this lets the while condition to fail and lets Process Pi enter its critical section. Subsequently for Process Pj in its own version of Pi, sets its own flag[j]=true indicating its willingness to enter its critical section and subsequently assigning turn=j.

Now the critical section condition for Pj is while(flag[i] && turn==i). This condition fails because Pj has initialized turn=j. So with the failing of the critical section condition for Pj, it enters its own critical section thereby violating the mutual exclusion principle as already Pi is in its critical condition.

b)Based on above explanation we can see that even if flag[i] and flag[j] are set to TRUE still the critical section condition fails for both processes and Pi and Pj enters their critical section.