PETERSON METHOD




Concurrent programming algorithm for mutual exclusion that allows two or more processes to share a single-use resource
without conflict, using only shared memory for communication.

Characteristics of Peterson Algorithm approach:


1. Mutual Exclusion:
The method provides mutual exclusion for sure. In entry section, the while condition involves the criteria for two variables

2.Progress:
An uninterested process will never stop the other interested process from entering in the critical section.
If the other process is also interested then the process will wait.

3.Bounded waiting:
The interested variable mechanism failed because it was not providing bounded waiting. However, in Peterson solution,
a deadlock can never happen because the process which first sets the turn variable will enter in the critical section for sure.
Therefore, if a process is preempted after executing line number 4 of the entry section then it will definitely get into the critical section in its next chance.

4.Portability:
This is the complete software solution and therefore it is portable on every hardware.Therefore a process cannot enter in the
critical section until the other process is interested and the process is the last one to update turn variable.

Demo

Steps

Lights

Input

Initially there will be already 2 process in the initial state.

For processing a process click on the respective process button and the process will be added to the respective state.

Output

The output will be according to the user input on the respective process for different states.

States like flag and turn of both the process is also shown above the initial state.

Lights