Question: . Consider the Peterson's algorithm for the critical section problem with two processes. Process 0: Process 1: Begin Begin while(true) while(true) { { (1) Flag

. Consider the Peterson's algorithm for the critical section problem with two processes. Process 0: Process 1: Begin Begin while(true) while(true) { { (1) Flag [O]=true; (1) Flag[1]=true; (2) turn=1; (2) turn=0; (3) while (flag[0] && turn==0); (3) while( flag [1] && turn==1); (4) Critical Section...; (4) Critical Section...; (5) flag [0] = false; (5) flag[1] = false; } } End End i) If the two statements (1) and (2) are swapped in both processes, state whether the altered code still satisfies the three requirements of the critical section problem. Explain which requirement has been violated. ii) If we change the logical operator in the condition of the while statement (Line 3) from and to or (i.e., while(flag[1-i] && turn==1-i) becomes while(flag[1-i] || turn==1-i)), state whether the altered code still satisfies the three requirements of the critical section problem. Explain which requirement has been violated. . Consider the Peterson's algorithm for the critical section problem with two processes. Process 0: Process 1: Begin Begin while(true) while(true) { { (1) Flag [O]=true; (1) Flag[1]=true; (2) turn=1; (2) turn=0; (3) while (flag[0] && turn==0); (3) while( flag [1] && turn==1); (4) Critical Section...; (4) Critical Section...; (5) flag [0] = false; (5) flag[1] = false; } } End End i) If the two statements (1) and (2) are swapped in both processes, state whether the altered code still satisfies the three requirements of the critical section problem. Explain which requirement has been violated. ii) If we change the logical operator in the condition of the while statement (Line 3) from and to or (i.e., while(flag[1-i] && turn==1-i) becomes while(flag[1-i] || turn==1-i)), state whether the altered code still satisfies the three requirements of the critical section problem. Explain which requirement has been violated
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
