Goseeko blog

What is Deadlock?

by Team Goseeko

A deadlock happens when a set of processes becomes stuck because each one is holding a resource and waiting for another to get it.

Consider the situation when two trains are approaching each other on the same track and there is only one track: once they are in front of each other, neither train can move. In operating systems, a similar situation happens when two or more processes hold some resources while waiting on resources owned by other processes (s). In the picture below, Process 1 is holding Resource 1 and waiting for Process 2 to acquire Resource 2, while Process 2 is waiting for Resource 1.

Deadlocks required certain conditions

  1. Mutual exclusion : Only mutually exclusive sharing of a resource is possible. If two processes can’t use the same resource at the same time, this is what it means.
  1. Hold and wait : A procedure waits for some resources while simultaneously holding another resource.
  1. No preemption : The process, once scheduled, will be carried out until it is completed. In the meanwhile, the scheduler is unable to schedule any further processes.
  1. Circular  wait : All processes must wait for resources in a cyclic fashion, so that the final process is waiting for the resource that the first process is holding.

Advantages 

  • For operations that perform a single burst of action, this situation is ideal.
  • For Deadlock, there is no need to prepare ahead of time.
  • When used to resources whose state can be readily saved and restored, this strategy is quite useful.
  • Compile-time checks could be used to ensure this.
  • Because the problem is solved during system design, no run-time computation is required.

Disadvantages  

  • The start of the process is delayed.
  • Processes must anticipate future resource requirements.
  • Preempts far more than is necessary.
  • Allows incremental resource requests to be denied.
  • Preemption losses are unavoidable.

Interested in learning about similar topics? Here are a few hand-picked blogs for you!

You may also like