Peterson’s Solution – Solutions for Critical Section Problem

  • August 27, 2021
  • Aashish Mishra

Case 1: turn = 0 or 1

critical section

This solution allows Mutual Exclusion for 2 process.

But there is strict alteration, P1 then P2 and so on…
Means No progress.
Therefore, It is not a correct solution.

Here, processes are never asked whether it want to enter the c.s. or not.


Case 2: Lets say, now we create a boolean array of Flag

One value of P1and the other for P2. If the process is interested in c.s. must
Reflect its flag value as True.

critical section


This solution allows Mutual Exclusion.
If P2 do not want to go to c.s. then P1 can do again and again(due to flag)
So, No Strict alteration.
But if P1 wants to go to c.s and executed flag[0] = T and due to some reason
pre-empted and then P1 wants to go to c.s. and executed flag[1] = True.
Now flag array is TT

No process can go to c.s (Deadlock Condition)
Therefore, No progress.

Case 3: Peterson’s Solution OR Decker’s Algorithm
Turn = 0 or 1 Flag

 peterson problem

It allows both Mutual Exclusion and progress.
It also supports Bounded Wait.
But applicable for two processes only.