Question: Suppose you have two processes using Peterson's Algorithm. If the two processes try to enter the critical section at the same time, how is mutual
Suppose you have two processes using Peterson's Algorithm. If the two processes try to enter the critical section at the same time, how is mutual exclusion enforced?
The flag and turn is set before checking to enter the critical section. When testing to enter the critical section only one process can "pass" the test, since turn can be set to only one value.
The turn variable can only be set to one value. So even if both flag variables are set, one of the processes will unset their flag.
When a process finish with the critical section, it will unset it's flag, and set the turn to the other processes. So even if they try to enter at the same time, one process can let the other in afterwards.
When a process finishes with the critical section, it will unset it's flag. So even if the processes try to enter at the same time, one process can let the other in afterwards.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
