Skip to content
Related Articles

Related Articles

Deadlock Prevention Policies in Distributed System

Improve Article
Save Article
Like Article
  • Last Updated : 12 Jan, 2022

A Deadlock is a situation where a set of processes are blocked because each process is holding a resource and waiting for a resource that is held by some other process.

There are four necessary conditions for a Deadlock to happen which are: 

  • Mutual Exclusion: There is at least one resource that is non-sharable and can be used by only one Process at a time.
  • Hold and Wait: A process is holding at least one Resource and waiting for another.
  • No Preemption: A resource cannot be taken from a process until it releases the resource.
  • Circular Wait: At least two processes should form a circular chain by holding a resource and waiting for a resource that is held by the next process in the chain.

So the above four conditions are necessary for a deadlock to occur, if any one of the above four conditions is prevented, we can prevent a Deadlock to occur. There are 2 ways to prevent deadlock in a distributed system.

  • Ordered Request
  • Collective Request

Ordered Request

As the name suggests, in this Deadlock Prevention method, each resource type is assigned a certain level to maintain a resource request policy for a process. This is known as the Resource Allocation policy. For each Resource, a global level number is assigned to impose ordering of all resource types. While requesting for a resource, a Process has to make sure that it does not request for a resource whose level order is lower than the highest-level order resource it currently holds. It can only request resources higher than the highest level resources, held by the process. Refer to the below example for a much better understanding. Suppose there are 10 resources from level 1 to 10, and 10 is the highest level order resource. If a Process currently has resources 5 and 8, it cannot request a resource below 8, it can only request resources 9 and 10. Like, the process cannot make a request for Resource 7, while holding resource 8. This method does not mean that requests should be made in increasing order of sequence. Before sending a request for resource 7, it has to release the held resource 8. After releasing 8, it can acquire 7. It is allowed because currently, it does not hold a resource higher than 7.

The Method makes sure that the Circular Wait condition is not reached and if one of the deadlock conditions is denied, the deadlock will be prevented.

Disadvantages:

  • A Process that has resource request orders in increasing order levels with respect to Resource Allocation Policy, will utilize all the resources and will waste the resources.
  • For Example: Take the reference of the above example, if a process has a resource request order from 1 to 10. It will acquire all resources and this degrades resource utilization.

Collective Request

This method prevents the Hold and Wait for condition by using any of the following Resource Allocation Policies :

  • This Resource Allocation Policy ensures that a Process requests for all the required resources before the execution of the process. If any of the required resources are not available, the request is not granted. Example: A Process requires 3 resources for its execution, if all the 3 resources are available, the request is granted and all 3 resources are allocated. But if any one of the 3 resources is not available, then none of the 3 resources will be allocated and the request is rejected.

  • In this Resource Allocation Policy, the Processes have to ensure that before requesting any resource, it should not hold any resource. That is, it should release all of its current resources before making any request for new resources. While requesting any resource, the process should not hold any resources.
     

  • In both of the above Resource Allocation Policies, the Hold and Wait condition of Deadlock can’t be reached and thus the Deadlock is prevented.

Disadvantages:

  • It leads to low resource utilization.
  • Process Starvation is also possible because, if there is a process with high resource needs, its request acceptance will get delayed.
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!