89.1k views
0 votes
Two processes, P1 and P2, need to access a critical section of code. Consider the following synchronization construct used by the processes :

Process P1 :
while(true)
{
w1 = true;
while(w2 == true);
Critical section
w1 = false;
}
Remainder Section

Process P2 :
while(true)
{
w2 = true;
while(w1 == true);
Critical section
w2 = false;
}
Remainder Section

Here, w1 and w2 are shared variables, which are initialized to false. Which one of the following statements is TRUE about the above construct?
a) It does not ensure mutual exclusion
b) It does not ensure bounded waiting
c) It requires that processes enter the critical section in strict alternation
d) It does not prevent deadlocks, but ensures mutual exclusion

User Kerim
by
8.2k points

1 Answer

1 vote

Final answer:

The synchronization construct ensures mutual exclusion by preventing both processes from being in the critical section simultaneously. However, it can lead to deadlock if both processes set their intent flags before checking each other's flags, resulting in both waiting indefinitely. Therefore, the correct answer is that it ensures mutual exclusion but does not prevent deadlocks.

Step-by-step explanation:

The synchronization construct provided by the student comprises two while loops that run infinitely for the processes P1 and P2. Both processes use shared variables w1 and w2 to indicate the desire to enter the critical section. Mutual exclusion is required for correct synchronization so that no two processes are in the critical section simultaneously.

In this construct, Process P1 sets w1 to true to signal its intent to enter the critical section and waits while w2 is true, indicating Process P2 is in or waiting for the critical section. Similarly, Process P2 sets w2 to true when it wants to enter the critical section and waits as long as w1 is true. There are two potential outcomes:

  • If one process is in the critical section, the other cannot enter, ensuring mutual exclusion.
  • However, this construct can lead to a deadlock if both processes set their respective flags before entering the loop to check the other's flag. Both will wait indefinitely for the other to release the critical section, hence it does not prevent deadlocks.

Based on the information given:

  • It ensures mutual exclusion since both processes can't enter the critical section simultaneously.
  • It does not prevent deadlocks because if both processes set their respective flags at the same time, they will wait forever.

The correct statement about the above construct is: d) It does not prevent deadlocks, but ensures mutual exclusion.

User Takamitsu Mizutori
by
7.8k points