Deadlock Avoidance Methods


In the last post we discussed about the 4 necessary conditions for Deadlock to occur. Today, we going to see how we can avoid deadlock in our system. There are several ways to avoid deadlock, let's look each one of them one by one. This topic is an important part of deadlock. So, let's start, shall we ?

Deadlock Avoidance Methods

The four Deadlock avoidance methods are:
1. Prevention
2. Avoidance
3. Detection and Recovery
4. Ignorance
Make a note of one thing that whatever avoidance methods are discussed above they are applicable in real life as well. Like, the first one is prevention which means that we shall make such an environment that problem never ever arises. Otherwise we can choose avoidance which means we choose a solution less efficient than prevention solution which can avoid problems. Or we can choose detection and recovery which means that we let the problem to occur and then we choose a solution. Or we can choose ignorance which means that we are ignoring the problems.

So in the above paragraph you saw that the 4 deadlock prevention methods are also applicable in real life scenarios.

Now let me give you a real life example so that you can relate it better.Consider you are having end-semester exams.
1. There must be some students in your class who studied for the end-sem sincerely from day 1.  So those students gave their exams and passed the semester with good marks. So, observe that these students used the prevention method i.e they took preventive measures prior the exams.
2. Now there must be some students who study the last night of exam as they just don't want to get failed in the exam. So, these are the students who choose avoidance method because there objective was not to get good marks and they just wanted to get passed.
3. There are some student who thinks that first they shall give the exams and after 2 or 3 exams they will decide what to do after. So, these are the students who follow detection and recovery method.
4. And at last we have those student who don't care about exams and they just ignore it. So, these are the students who follow ignorance method.

In the above example you might think that prevention or avoidance is the best method but the method you choose to solve your problem totally depends on time taken to solve a problem or space taken to solve a problem.

Prevention

It means that system shall we designed which violate at least one of the four conditions of deadlock so that deadlock never occurs.

Avoidance

In this a system maintains a set of data using which it takes a decision to entertain a request or not to be in safe state. It means that whenever a process wants resource we first checks whether giving that resource to the process don't lead to deadlock. So, in this approach we avoid deadlock during runtime.

Detection and Recovery

In this approach we first let the deadlock to occur and once we detect deadlock we solve it.

Ignorance

In this approach we ignore the problem as if it has never occured.

Conclusion
You shall never think that prevention is better or avoidance is better because it totally depends on the problem that we are solving because in solving a problem we want the cost to be minimized and efficiency to be maximized. So, it might be possible that sometimes we will have to ignore the problems also.
Post a Comment (0)
Previous Post Next Post