AfterAcademy Tech
•
08 Nov 2019

In this blog, we will learn one of the most important concepts of Operating System i.e. Deadlock. We will find what a Deadlock is and we will also see the four necessary conditions of Deadlock. So, let's get started.
If you are already familiar with deadlock and its four necessary conditions, then you can skip this blog and read What are Deadlock handling techniques in Operating System?
Deadlock is a situation where two or more processes are waiting for each other. For example, let us assume, we have two processes P1 and P2. Now, process P1 is holding the resource R1 and is waiting for the resource R2. At the same time, the process P2 is having the resource R2 and is waiting for the resource R1. So, the process P1 is waiting for process P2 to release its resource and at the same time, the process P2 is waiting for process P1 to release its resource. And no one is releasing any resource. So, both are waiting for each other to release the resource. This leads to infinite waiting and no work is done here. This is called Deadlock.

If a process is in the waiting state and is unable to change its state because the resources required by the process is held by some other waiting process, then the system is said to be in Deadlock.
Let's take one real-life example to understand the concept of Deadlock in a better way. Suppose, you are studying in a school and you are using the bus service also. So, you have to pay two fees i.e. bus fee and tuition fee. Now, think of a situation, when you go for submitting the bus fee and the accountant says that you have to submit the tuition fee first and then the bus fee. So, you go to submit the tuition fees on the other counter and the accountant there said that you have to first submit the bus fees and then the tuition fees. So, what will you do here? You are in a situation of deadlock here. You don't know what to submit first, bus fees or tuition fees?
There are four different conditions that result in Deadlock. These four conditions are also known as Coffman conditions and these conditions are not mutually exclusive. Let's look at them one by one.



Deadlock will happen if all the above four conditions happen simultaneously.
There is a difference between a Deadlock and Starvation. You shouldn't get confused between these. In the case of Deadlock, each and every process is waiting for each other to release the resource. But in the case of starvation, the high priority processes keep on executing and the lower priority processes keep on waiting for its execution. So, every deadlock is always starvation, but every starvation is not a deadlock. Deadlock is infinite waiting but starvation is not an infinite waiting. Starvation is long waiting. If the higher priority processes don't come, then the lower priority process will get a chance to be executed in case of starvation. So, in the case of starvation, we have long waiting and not infinite waiting. You can learn more about starvation from here.
Read our blog What are deadlock handling techniques in Operating System? to find ways of handling deadlock if it occurs.
That's it for this blog. Hope you enjoyed this blog.
Do share this blog with your friends to spread the knowledge. Visit our YouTube channel for more content.
Keep Learning 🙂
Team AfterAcademy!
AfterAcademy Tech
In this blog, we will learn what is a deadlock situation, what are various deadlock handling techniques like deadlock prevention, deadlock avoidance, deadlock detection, and deadlock ignorance.

AfterAcademy Tech
In this blog, we will learn four techniques of deadlock handling i.e. deadlock prevention, deadlock avoidance, deadlock detection and recovery, and deadlock ignorance. So, let's learn about these.

AfterAcademy Tech
In this blog, we will learn about a specific deadlock, i.e., Phantom deadlock, and will also see some examples of its occurrence.

AfterAcademy Tech
In this blog, we will see one of the deadlock avoidance methods i.e. Banker's Algorithm. In this algorithm, we will discuss that if we are given the number of resources available and the number of resources required by the process then we can tell that if the system will go in deadlock or not. We will understand this concept with the help of an example.
