With regard to proposal 4 (Peterson\'s Solution), if there are two processes Pro
ID: 3732721 • Letter: W
Question
With regard to proposal 4 (Peterson's Solution), if there are two processes Process 0 and Process 1 and Context Switching happens like the following sequence, please complete the execution flow and answer the question whether both these processes can enter the critical section #define FALSE #define TRUE 1 int turn; 5 int interestedt2]-(e,e); 6 7 void enterregion(int process) int other; 10 other = 1-process; interested [process] TRUE; turnprocess; while (turnprocess && interested[other] 12 13 14 15 16 l 17 18 void leave..regionCint process) 19 20 21 l TRUE) /* busy waiting */ interested[process]FALSE;Explanation / Answer
We denote process 0 by P0 and process 1 by P1.
P0:(7-12)
other=1
interested[0]=TRUE
P1:(7-12)
other=0
interested[1]=TRUE
P0:(13-14)
turn = 0
while(turn == 0 && interested[1] == TRUE)
(As both the conditions in the while loop is true so, P0 will not enter the critical section and will busy wait)
P1:(13-14)
turn = 1
while(turn == 1 && interested[0] == TRUE)
(As both the conditions in the while loop is true so, P1 will not enter the critical section and will busy wait)
P0:(14)
while(turn == 0 && interested[1] == TRUE)
(now the first condition is false as turn is set to 1 by P1. Therefore, P0 will break the while loop and enter the critical section).
P1:(14)
while(turn == 1 && interested[0] == TRUE)
(Still both the conditions are true so, P1 will continue to busy wait until P0 leaves the critical section and makes interested[0]=FALSE)
Therefore, Two processes can never be together in the critical section in Peterson's Solution.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.