Consider the following implementation as a solution to the critical section problem for two processes P0 and P1 with id 0 and 1, respectively.

int flag[2] = {0, 0};

int turn = 0;

void lock (int id) /* id = 0 or 1 */

{

turn = id ^ 1; /*s1*/

flag[id] = 1; /*S2*/

/* ‘^’ is the bitwise XOR*/

while (flag [id ^1]) && turn == (id ^ 1));

}

void unlock (int id)
{

flag[id] = 0;

}

Which of the following statements are correct?

1
Solution leads to a deadlock
2
Mutual exclusion is guaranteed if S1 and S2 are interchanged 
3
Mutual exclusion is guaranteed
4
None of the above

Sponsored

hivanix.in

Visit

This quiz is brought to you by hivanix.in

🌐 Web App Development

Quick Navigation