Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Q4. (Inter Processing Communications) With regard to proposal 4 (Peterson’s Solu

ID: 3732665 • Letter: Q

Question

Q4. (Inter Processing Communications)

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.

1    #define FALSE 0

2    #define TRUE 1

3    

4    int turn;                       

5    int interested[2] = {0,0};              

6    

7    void enter_region(int process)

8    {

9        int other;                    

10    

11        other = 1-process;            

12        interested[process] = TRUE;   

13        turn = process;

14        while (turn == process && interested[other] == TRUE)

15            ;    /* busy waiting */

16    }

17    

18    void leave_region(int process)

19    {

20        interested[process] = FALSE;

21    }

Given sequence:

Process 0 Process 1 Process 1 enter region: 7-12 Context Switching enter region: 7-12 Context Switching enter region: 13-14 Context Switching

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.