318 views
4 votes
4 votes

Consider the following synchronization construct used by two the processes

turn1 = true;
turn2 = true;
Process 1
...
while(true)
{
    turn1 = true;
    while(turn2);
    /* Critical Section */
    turn1 = false;
}
...
Process 2
...
while(true)
{
    turn2 = true;
    while(turn1);
    /* Critical Section */
    turn2 = false;
}
...


Which one of the following statements is/are TRUE?

  1. The proposed solution prevents deadlock but fails to guarantee mutual exclusion.
  2. The proposed solution guarantees mutual exclusion but fails to prevent deadlock.
  3. The proposed solution guarantees mutual exclusion and prevents deadlock.
  4. The proposed solution fails to prevent deadlock and fails to guarantee mutual exclusion.

 

1 Answer

Best answer
1 votes
1 votes
The given code guarantees mutual exclusion but since both turn1 and turn2 are initialized to TRUE both process $1$ and process $2$ will enter the infinite while loop without any progress. So, there is deadlock.

Correct answer: B.
selected by
Answer:

Related questions

3 votes
3 votes
1 answer
1