179 views
2 2 votes

Consider the following solution for process $P_i$:

$\texttt{while (turn != i);}$

$\texttt{Critical Section}$

$\texttt{turn = j;}$

Which of the following statements are correct?

  1. The solution satisfies mutual exclusion.
     
  2. The solution uses busy waiting.
     
  3. The solution may violate progress if $\texttt{turn = j}$, but process $P_j$ remains in its remainder section.
     
  4. Process $P_i$ can immediately re-enter its critical section after leaving, regardless of the value of $\texttt{turn}$.

1 Answer

1 1 vote

Statement (A) is correct.

The shared variable $\texttt{turn}$ can contain only one process identifier at a time. Therefore, only the process whose identifier equals $\texttt{turn}$ can enter.

Statement (B) is correct.

A process repeatedly checks:

$\texttt{while(turn != i);}$

while waiting. This consumes CPU time and is called busy waiting.

Statement (C) is correct.

Suppose $P_i$ wants to enter, but $\texttt{turn = j}$.

Even if $P_j$ does not want to enter and remains in its remainder section, $P_i$ cannot proceed until $P_j$ changes $\texttt{turn}$.

Thus, a process outside its critical section can prevent an interested process from entering. This violates progress.

Statement (D) is incorrect.

After leaving its critical section, $P_i$ assigns:

$\texttt{turn = j;}$

Therefore, it cannot re-enter until $P_j$ returns the turn.

Answer:
Position:
Show:

Related questions

3 3 votes
1 1 answer
284
284 views
GO Classes asked Jul 25
284 views
Consider the following entry and exit code used by two processes:$\texttt{while(lock);}$$\texttt{lock = TRUE;}$$\texttt{Critical Section}$$\texttt{lock = FALSE;}$Initiall...
4 4 votes
1 1 answer
226
226 views
GO Classes asked Jul 27
226 views
Two processes use the following symmetric solution:For process $P_i$:$\texttt{flag[i] = TRUE;}$$\texttt{while (flag[j]);}$$\texttt{Critical Section}$$\texttt{flag[i] = FA...
3 3 votes
1 1 answer
246
246 views
GO Classes asked Jul 25
246 views
Which of the following statements are correct?Mutual exclusion ensures that if one process is executing in its critical section, no other process can execute in its criti...
3 3 votes
0 0 answers
789
789 views
hacker16 asked Nov 9, 2017
789 views
Turn is shared variable but the values are not shared.Explain?