 Hello everyone. Now we are going to learn about deadlock characterization. So the learning outcome of this session are at the end of this session student will be able to describe necessary conditions for deadlock and student will be able to identify whether deadlock exists or not in the system using resource allocation graph. Now as in previous video we already studied when process enters in deadlock state, then system is in deadlock state. So in deadlock state processes never finish their execution and all system resources are tied up. So as system resources are tied up and processes are investing state, they prevent other jobs from starting. So no fruitful task is performed. So how this situation occurs in the system? So in deadlock characterization we are going to study four necessary conditions which are necessary for deadlock to occur in the system. So deadlock can arise if four conditions hold simultaneously in the system. First is mutual exclusion. In this case only one process at a time can use a resource. If the resource is already used by that process then next process will enter in waiting state. That process will not use that resource. So here as we can see if process P1 is using resource R then P2 must wait for that resource. But if P2 is using the resource R then P1 must wait for the resource. This situation is called as a mutual exclusion. Then next is hold and wait. A process holding at least one resource is waiting to acquire additional resource held by other process means process is already holding one resource. For example here P1 is already holding R1 and it is waiting for R2 which is already used by P2. So this is what the process is holding one resource and waiting for another resource that is hold and wait. And next is no preemption. Now no preemption means here a resource can be released only voluntarily by process holding it. After that process has completed its task means the resource once it is allocated to the process then that resource is never be allocated till process complete its execution. That resource will be with that process till it completes its execution. It is never preempted. Next condition is circular wait. So in circular wait suppose there exists a process P0 to Pn and these processes are waiting like that P0 is waiting for P1, P1 is waiting for P2, P2 waiting for P3, P4 waiting for P5 and again P5 is waiting for P1. So this situation is called as a circular wait means here one process previous process is waiting for next process then next process then next process and the last process is again waiting for the first process. So this situation is called as a circular wait. So when these all four conditions are exist simultaneously in the system then we can say that deadlock occur. That four conditions are mutual exclusion, hold and wait, no preemption and circular wait. If all these four conditions are there then deadlock occur in the system. So just pause the video and write what in what situation deadlock occurs in the system. So deadlock occur in the system whenever all four conditions hold simultaneously in the system. Now the next concept we are going to study is resource allocation graph. How resource allocation graph plays an important role for the detection of the deadlock. Now what is this resource allocation graph? It is a system resource allocation graph which contains set of vertices V and set of edges. It is a directed graph with set of vertices and set of edges. Set of vertices are divided into two parts. First is number of processes P1 to Pn and number of resources R1 to Rm. So processes and resources are denoted and as a vertices and request made by process to the resource and allocation of the resource to process is indicated as a edges. So the directed edge from process to resource is called as a request edge and the directed edge from resource to process is called as an assignment edge. So we will see the notations which are used in resource allocation graph. First is process. Process is denoted as a circle with its number. Then resources are indicated by rectangular block with instances as a dot or square. Now here I use square in your book we have a dot for instances of the resource. Now here when process PI request for resource RJ then that request edge is shown. However one of the instance of the resource is allocated to the process then it is shown as an assignment edge. Now consider a resource allocation graph here we have three processes and four resources. So we have a set of sets of process, resource and edges. Now set P will contain P1, P2, P3, R will contain R1, R2, R3, R4 and now the set of edges from P1 to R1, R1 to P2, R3 to P3, R2 to P2, R2 to P1 and then we have P3 to R4 and P2 to R3. So these are the set of edges. So this shows the resource instances and the process states with request edge and assignment edge. Here this is nothing but the assignment edge which is from R1 to P2 and P2 to R3 is nothing but the request edge. So this is how the resource allocation graph can be drawn based on number of processes, number of resources and how the request and allocation is given to the process. Now in the resource allocation graph if there is no cycle then we can say that there is a no deadlock, if no cycle. Now for what purpose RAGE is used? RAGE is used to check whether system is in deadlock state or not. Then how it will be checked? If your resource allocation graph contains a cycle then only that it will exist a deadlock. If there is no cycle then there is a no deadlock. So as shown here, if there is no cycle then there is no deadlock. If cycle exists then deadlock may exist in the system. If each resource type has exactly one instance then cycle implies that deadlock has occurred into the system. If we have only one instance then this we can say that there is a cycle from P1 to P2, P2 to P3 again P3 to P1. So this may says that deadlock may occur in the system or deadlock has occurred. Now we will see that for single instance the deadlock cycle is a necessary and sufficient condition for existence of the deadlock. So if we have a single instance then we can say that if there is a cycle deadlock surely occurred in the system. Now if we have multiple instances of the resource type, multiple instances of the resource type if cycle exists then it does not imply that deadlock has occurred. So as shown here we have three processes and we have four resources and this is how the request and assignment age are given. Now this is the current situation. Now suppose process P3 make request for an instance of resource type R2. Then we will have the cycles like this P1 to R1, P2 to R3, R3 to P3, P3 to R2 and again from R2 to P1 or R2 to P2. So this there may exist a cycle, there may exist two cycles from P1 to P3 to P1 or from P2 to P3 and again P3 to P2. But here whenever this cycle exists then we can say that this P1, P2, P3 are in deadlock state because both of the instance of R2 are one is given to P2 and one is given to P1 and P3 will enter in waiting state. So cycle exists so this is the deadlock state. But for whenever we have multiple instances then we can say that cycle is necessary but it is not sufficient condition for existence of the deadlock. For single instance cycle is necessary and sufficient condition for the existence of the deadlock. Now how this is necessary but not sufficient condition for existence of a deadlock that we will see. So consider the processes P1, P2, P3, P4 and the two resources R1 and R2 with two instances. So here we can say that we have a cycle from P1 to P3 and again from P3 to P1. So here we have a cycle but still there is a no deadlock. How? Because here process P4 may release an instance of resource type R2. Because it release that instance of resource type R2 it automatically that instance will be given to P3 and it break the cycle. So this cycle is called as a false cycle. So that is why we are saying that whenever we have multiple instance of resource type then deadlock is necessary but it is not sufficient condition for deadlock to occur into the system. There may exist a false cycle in case of multiple instance resource type. So this is how we can use resource allocation graph for detection of the deadlock whether that deadlock may occur into the system or not. So these are the references.