Question 22
Consider the following scenario where two processes are sharing a common variable which is modified in the critical section.
Global setup
int lock[2]= {0,0}, choice = 0;Process 1
1 while(1){2 lock[0] = 1;3 choice = 1;4 while(lock[1] && choice == 1);5 // critical section6 lock[0] = 0;7 // remainder section8 }Process 2
1 while(1){2 lock[1] = 1;3 choice = 0;4 while(lock[0] && choice == 0);5 // critical section6 lock[1] = 0;7 // remainder section8 }Select the correct statements about the above processes.
It achieves mutual exclusion.
It can cause deadlock.
Process 2 can enter the critical section multiple times before a context switch if Process 1 is in remainder section.
Process 2 can enter the critical section multiple times before a context switch if Process 1 is waiting to enter the critical section.