Peterson’s Algorithm | Peterson’s Solution
Peterson’s Solution:
Peterson’s Algorithm is a simple algorithm that can be run by two processes to ensure mutual exclusion for one resource.
It does not require any special hardware.
It uses busy waiting technique.
Peterson's Solution is a 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.
Peterson’s Algorithm:
The algorithm uses two variables, flag and turn.
The variable turn indicates whose turn it is to enter the critical section.
If turn == i, then process Pi is allowed.
The flag array is used to indicate if a process is ready to enter the critical section.
Flag[i] = true implies that process Pi is ready.