Question: Here is the code about Petersons Solution, please check whether this code is correct, if not, please use green color to mark it and correct
Here is the code about Petersons Solution, please check whether this code is correct, if not, please use green color to mark it and correct it
Assume that the load and store instructions are atomic; that is, cannot be interrupted
The two processes share two variables:
int turn;
Boolean flag[2]
The variable turn indicates whose turn it is to enter the critical section
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!
Process Pi
do {
flag[i] = true;
turn = j;
while (flag[j] && turn == i);
critical section
flag[j] = false;
remainder section
} while (true);
Process Pj
do {
flag[j] = true;
turn = i;
while (flag[i] && turn == j);
critical section
flag[i] = false;
remainder section
} while (true);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
