FOR FREE CONTENT

Peterson Algorithm: 

 

# Previously we have seen that turn variable or Decker’s algorithm has a problem of progress and turn variable with special variable has a problem of bounded waiting.

 

# But Peterson algorithm solves both problem progress and bounded waiting by using both turn and want_to_enter variable. 

 

# Peterson's solution is restricted to two processes that alternate execution between their critical sections.

 

Peterson Algorithm

  • S/W mechanism at user mode
  • Busy waiting solution
  • 2 Process solution

 

 

Note: Here other = 1 - process means when P0 occurs, then process = 0 and other = 1 – 0 = 1.

When P1 occurs, then process=1 and other = 1 - 1 = 0.

 

Example of Peterson algorithm:

 

Initially 

    want_to_enter[0]=false;

    want_to_enter[1]=false;

 

            

Peterson Algorithm

1)  Mutual Exclusion - Yes

2)  Progress - Yes

3)  Bounded wait - Yes

4)  Portable - Yes because it is executed in user mode.

 

Peterson satisfy all the conditions so, Peterson is better than all among busy waiting solution algorithms for process synchronization. 

 

Disadvantage of Peterson algorithm:

1. Busy waiting

2. Priority inversion problem: Here higher priority process gets into the loop when the lower priority process is in CS.