Question 1
Consider the following scenario where two processes are sharing a common variable.
Global setup
int turn = 1;Process 1
while(1) { while(turn == 2); // lock // critical section turn = 2; // unlock // remainder section}Process 2
while(1) { while(turn == 1); // lock // critical section turn = 1; // unlock // remainder section}Which of the following statements about the given processes is correct?
Process 1 and Process 2 will enter their critical sections simultaneously, leading to race conditions.
Process 1 will always enter its critical section before Process 2.
Process 2 will always enter its critical section before Process 1.
Deadlock can occur if both processes try to enter their critical sections simultaneously.