edited by
39,076 views
100 100 votes

Two processes $X$ and $Y$ need to access a critical section. Consider the following synchronization construct used by both the processes$$\begin{array}{|l|l|}\hline \text{Process X}  &  \text{Process Y}  \\ \hline  \text{/* other code for process X*/} & \text{/* other code for process Y */} \\  \text{while (true)} & \text{while (true)} \\ 
\text{\{} & \text{\{} \\
\quad\text{varP = true;} & \quad \text{varQ = true;} \\
\quad\text{while (varQ == true)} &\quad \text{while (varP == true)}\\ 
\quad\text{\{} & \quad\text{\{}  \\ 
\quad\quad\text{/* Critical Section */} & \quad\quad\text{/* Critical Section */} \\ 
\quad\quad\text{varP = false;} &\quad\quad \text{varQ = false;} \\
\quad\text{\}} & \quad\text{\}} \\
\text{\}} & \text{\}} \\
\text{/* other code for process X */} & \text{/* other code for process Y */}\\
\\ \hline  \end{array}$$

Here varP and varQ are shared variables and both are initialized to false. Which one of the following statements is 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

7 Answers

Best answer
136 136 votes

When both processes try to enter critical section simultaneously, both are allowed to do so since both shared variables varP and varQ are true. So, clearly there is NO mutual exclusion. Also, deadlock is prevented because mutual exclusion is one of the necessary condition for deadlock to happen. Hence, answer is (A).

edited by
58 58 votes

the answer is A.. the main thing here to watch in question is that there is no semicolon after while loop. and so When both processes try to enter critical section simultaneously,both are allowed to do so since both shared variables varP and varQ are true. So, clearly there is NO mutual exclusion. Also,deadlock is prevented because mutual exclusion is one of the conditions for deadlock to happen. 

2 2 votes

With having context switch at every instance, we can see that at one time, both X and Y are in Critical section, and after one such iteration of the while loop either of X or Y depending on the order of context switches, one of them, will move out from The Critical section.

And only one of them will be there forever.

This clearly shows that initially, there was no mutual exclusion as we got one case where both P and Q were in the critical section.

 

There is essentially no deadlock

But there is no progress and no bounded waiting.

1 1 vote

There will be dead lock, but mutual exclusion is satisfied.

suppose X executes and sets p to true then preempts,  now Y executes and sets q to true, now when Y goes to while statement it will loop forever, same happens with X.

Most answers are misinterpreting the definition of deadlock and misunderstanding the mutual exclusion condition of Deadlock characteristics with mutual exclusion of critical section.

The definition of Deadlock is :Deadlock - Wikipedia

Also if we find even a single case in which deadlock occurs then the solution is said to not prevent deadlock. 

Mutual exclusion in synchronization means only one process should enter cs, while mutual exclusion of deadlock characteristics is about a resource being owned by only a single process. Take printer for example, only one computer can use it at a time, so this ME can not always be dissatisfied. which now brings me to another point:

ME of synchronization is property that must be enforced by a solution, while ME of deadlock characteristics is a property that should be removed to prevent deadlock. Do you see the difference? in one case we need ME to be present while in another case we need it to go away.

Students are confusing Mutual exclusion in both cases, when working with semaphore mutual exclusion doesn’t have anything to do with deadlock, both are different. 

So answer is B

1 flag:
✌ Edit necessary (Shashank_Dwivedi)
0 0 votes

There will be dead lock, but mutual exclusion is satisfied.

suppose X executes and sets p to true then preempts,  now Y executes and sets q to true, now when Y goes to while statement it will loop forever, same happens with X.

Most answers are misinterpreting the definition of deadlock and misunderstanding the mutual exclusion condition of Deadlock characteristics with mutual exclusion of critical section.

The definition of Deadlock is :Deadlock is any situation in which no member of some group of entities can proceed because each waits for another member, including itself, to take action, such as sending a message or, more commonly, releasing a lock.

Also if we find even a single case in which deadlock occurs then the solution is said to not prevent deadlock. 

Mutual exclusion in synchronization means only one process should enter cs, while mutual exclusion of deadlock characteristics is about a resouurce being owned by only a single process. Take printer for example, only one computer can use it at a time, so this ME can not alwasy be dissatisfied. which now brings me to another point:

ME of synchronization is property that must be enforced by a solution, while ME of deadlock characteristics is a property that should be removed to prevent deadlock. Do you see the difference? in one case we need ME to be present while in another case we need it to go away.

Students are confusing Mutual exclusion in both cases, when working with semaphore mutual exclusion doesn’t have anything to do with deadlock, both are different. 

So answer is B

Answer:
Position:
Show:

Related questions

51 51 votes
4 answers 4 answers
20.8k
20.8k views
go_editor asked Feb 16, 2015
20,766 views
Consider the following policies for preventing deadlock in a system with mutually exclusive resources.Process should acquire all their resources at the beginning of execu...
64 64 votes
8 answers 8 answers
32.8k
32.8k views
go_editor asked Feb 15, 2015
32,784 views
For the processes listed in the following table, which of the following scheduling schemes will give the lowest average turnaround time?$$\small \begin{array}{|c|c|c|} \h...
32 32 votes
4 answers 4 answers
11.3k
11.3k views
go_editor asked Feb 14, 2015
11,317 views
The exports and imports (in crores of $Rs$.) of a country from the year $2000$ to $2007$ are given in the following bar chart. In which year is the combined percentage in...
7 7 votes
4 answers 4 answers
8.3k
8.3k views
go_editor asked Feb 16, 2015
8,325 views
Consider the following software items: Program-$X$, Control Flow Diagram of Program-$Y$ and Control Flow Diagram of Program-$Z$ as shown belowThe values of McCabe's Cyclo...