Search code examples
operating-systemsynchronizationdeadlock

Deadlock prevention :Mutual Exclusion


Deadlock prevention say :

All four of the conditions are necessary for deadlock to occur, it follows that deadlock might be prevented by denying any one of the conditions.

Conditions

  1. Mutual Exclusion

  2. Hold and Wait

  3. No Premption

  4. Circular Wait

Now

Let us deny first one

  1. Mutual Exclusion

There are many examples to prove that Mutual Exclusion may lead to deadlock like here .

Now let us prevent this Mutual Exclusion .But the problem is that

The mutual exclusion condition must hold for non-sharable resources. That is, several processes cannot simultaneously share a single resource. This condition is difficult to eliminate because some resources, such as the tape drive and printer, are inherently non-shareable.check this.

Question/Doubt

We cannot eliminate Mutual Exclusion then **why is it one of the condition **??


Solution

  • We cannot Elimainate Mutual Exclusion then why is it one of the condition ??

    We cannot eliminate mutual exclusion in cases where we are dealing with non-shareable resources. So, it simply emphasizes that for special cases when we dealing with resources like tap drive and printer, which are inherently non-shareable, then we have to look at eliminating one of the other three options to prevent deadlock.

    Now Critical Section does not always mean that we are talking about physical resources. It can also mean that we are talking about a piece of code. And variables are resources that are inherently shareable resources. So in such cases we can eliminate mutual exclusion to prevent deadlock. But keep in mind thats rarely done, because if we had ensured mutual exclusion in the initial design, it was there to ensure correct implementation. So just to make you aware that deadlock could be prevented by preventing mutual exclusion, but it does not mean that its practically prevalent.