Question: Question 2 : Process Synchronization using Peterson's Algorithm Consider a system with two processes, P 1 and P 2 , that need to access a

Question 2: Process Synchronization using Peterson's Algorithm
Consider a system with two processes, P1 and P2, that need to access a shared resource.
They use Peterson's Algorithm for synchronization. Peterson's Algorithm is implemented as
follows:
c
Copy code
int turn;
boolean flag[2];
void P1(){
while (true){
flag[0]= true;
turn =1;
while (flag[1] && turn ==1){
// Busy-wait
}
// Critical Section
flag[0]= false;
// Remainder Section
}
}
void P2(){
while (true){
flag[1]= true;
turn =0;
while (flag[0] && turn ==0){
// Busy-wait
}
// Critical Section
flag[1]= false;
// Remainder Section
}
}
1. Explain how Peterson's Algorithm ensures mutual exclusion, progress, and bounded
waiting.
2. Compare and contrast Peterson's Algorithm with the Test-and-Set mechanism in terms
of efficiency and fairness. Which of the two would be more suitable for modern multi-core
processors, and why

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!