edited by
20,793 views
69 votes
69 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
edited by

6 Answers

0 votes
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

0 votes
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 - 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

Answer:

Related questions

42 votes
42 votes
5 answers
2
21 votes
21 votes
4 answers
3
35 votes
35 votes
6 answers
4
go_editor asked Feb 14, 2015
30,468 views
The maximum number of processes that can be in $\textit{Ready}$ state for a computer system with $n$ CPUs is :$n$$n^2$$2^n$Independent of $n$