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
- 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.
- Hold and wait : A procedure waits for some resources while simultaneously holding another resource.
- 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.
- 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!
- What is computer software?
- Phenomena of sorting algorithm?
- What is computer processor?
- Define recursion?
- What is SQL?