![]() |
VOOZH | about |
Deadlock is a condition where a set of processes becomes stuck and waits infinitely for the resources which are hold by other processes. To handle these types of problems, we use two strategies - Deadlock Prevention and Deadlock Avoidance.
Deadlock Prevention means blocking one of the conditions necessary for deadlock while deadlock avoidance refers to managing resource allocation in such a way that is safe and avoids unsafe states.
Deadlock prevention means blocking at least one of the four conditions required for deadlock to occur. If we are able to block any one of them then deadlock can be prevented.
The four conditions which need to be blocked are:-
Spooling and non-blocking synchronization algorithms are used to prevent the above conditions. In deadlock prevention, all the requests are granted in a finite amount of time.
In Deadlock avoidance we have to anticipate deadlock before it really occurs and ensure that the system does not go in unsafe state.It is possible to avoid deadlock if resources are allocated carefully. For deadlock avoidance we use Banker's and Safety algorithm for resource allocation purpose. In deadlock avoidance the maximum number of resources of each type that will be needed are stated at the beginning of the process.
| Factors | Deadlock Prevention | Deadlock Avoidance |
|---|---|---|
| Concept | It blocks at least one of the conditions necessary for deadlock to occur. | It ensures that system does not go in unsafe state |
| Resource Request | All the resources are requested together. | Resource requests are done according to the available safe path. |
| Information required | It does not requires information about existing resources, available resources and resource requests | It requires information about existing resources, available resources and resource requests |
| Procedure | It prevents deadlock by constraining resource request process and handling of resources. | It automatically considers requests and check whether it is safe for system or not. |
| Preemption | Sometimes, preemption occurs more frequently. | In deadlock avoidance there is no preemption. |
| Resource allocation strategy | Resource allocation strategy for deadlock prevention is conservative. | Resource allocation strategy for deadlock avoidance is not conservative. |
| Future resource requests | It doesn't requires knowledge of future process resource requests. | It requires knowledge of future process resource requests. |
| Advantage | It doesn't have any cost involved because it has to just make one of the conditions false so that deadlock doesn't occur. | There is no system under-utilization as this method works dynamically to allocate the resources. |
| Disadvantage | Deadlock prevention has low device utilization. | Deadlock avoidance can block processes for too long. |
| Example | Spooling and non-blocking synchronization algorithms are used. | Banker's and safety algorithm is used. |
Deadlock Prevention eliminates one of the necessary conditions for deadlock, but it may result in under-utilization of resources. On the other hand, Deadlock Avoidance allocates resources to avoid deadlock, but it requires information about future resource requests which may cause process delays. We need to choose the right strategy depending on the system requirements and resource demand.