Here is the Peterson's solution

I am also confused about the while loop part, if the condition in the while is not true, then how it is going to get into CS?

How does this Peterson's solution satisfy the conditions of Mutual exclusive, no-starvation and progress condition?

Thank you!

1

There are 1 best solutions below

0
On

The while loop here is working like a 'trap'. If the condition is true then it means that the other process is inside the Critical Section. Look at P0, if the turn is of 1, and the flag is true it will imply that P1 is inside the CS, and when P1 is done with CS, it will mark the flag as False, which will make the condition in while loop false. So P0 will get into the CS.

In order to get into CS, code will have to make the while loop 'False'. I hope it helps.