 Hello everyone, today we are going to learn about deadlock. So before starting with deadlock we are going to learn system model for deadlock. So learning outcome of this session are at the end of this session student will be able to describe system model required for deadlock. Now what is deadlock? As we know we have a multiprogramming environment. So in multiprogramming environment multiple processes execute simultaneously in the system and to execute that process the resources are allocated. Now resources can be anything, it can be hardware resource or software resource, it can be memory, it can be CPU, it can be registers. So different resources are allocated to the process. So whenever process requires a resource then that process must request for that resource. If that resource is available then that resource is allocated to the process. This is done by operating system but if resource is not available then what will happen? Process will enter into the waiting state because that resource is not available and process cannot continue its execution. So the process enters in waiting state and that process may never again change its state and it remains in waiting state for long period of time. So resources requested by the process may be held by some another waiting process. So here one process may request a resource which is already held by other process and that process itself is in waiting state and due to this situation all processes may enter into the waiting state and this situation is called a deadlock because no process is executing their task, the processes are in waiting state and no one can perform the task properly and that situation is called as a deadlock, they waste CPU cycles. So first we will see the system model required for deadlock. As we know for system we have a finite number of resources, means number of resources are not infinite, we always have finite number of resources. So if your resources are same then there are different instances of that resources. For example resource means what as I already explained resource means it can be a memory space, it can be a CPU cycles, files, registers, IO devices whatever it is. So if we have two CPU then we can say that resource is CPU and we have two instance for that CPU resource. Similarly if we have five printer then it implies that we have a resource printer but as we have five printers there are five instance of that resource printer. So process must request an instance of resource type means if we have multiple instances of the resource then the process must request an instance of a resource type and if that instance of resource type is available then it is allocated to the process but if this is not possible means if it is not possible to allocate the resource or allocate the instance to that process that means that instances are not identical and we cannot allocate that instance to the process. So as I already told before using any resource process must request a resource. Once process request a resource if that resource is available then it is given to the process, process uses that resource and then after using that resource process must release that resource. Why to release? Because if another process is waiting for that resource if this currently executing process finish its use of that resource then it can release it so that other process can use that resource. So process must release a resource after using it. So the number of resources requested may not exceed the total number of resources available. This means the processes never request a resource which are greater than available resources that means if we have only two printers then system cannot request or the process cannot request for three printers okay. So available are only two then how it can request for three then error message should be generated. So process utilize a resource in following sequence how it utilizes a resource. First it request a resource then it use that resource then it release that resource okay. Now just pause the video and give answer what will happen if process request a resource which is already held by some another process. If the resource is already held by other process then the process will enter into the waiting state okay. Now as I am saying that process must request a resource then use it and then release it. So to request and release a resource processes must use system call okay. Now system call is nothing but a predefined functions in operating system which are used by the processes whenever they need it. So we can say that we have a system call for a device that is request and release means whenever process wish to access a device then there are a system call which are request and release. For files we are using open and close in our programming we use open and close system calls for the file. Similarly for memory we use ALOCK and FREE okay. These system calls are already defined in the system. Then for semaphore we have wait and signal system calls and how these system calls are maintained. Actually these system calls are already present there as a library system library in operating system and whenever process request for a resource at that time these system calls are called. We already know the example of file open and close system call which we use in our programming language. Now what is the role of system table? System table here maintains the record that which resource is allocated to which process and which resource is free by which process. So here system call maintains all the record of the allocation and deallocation of the resources. Now we can say that process is in deadlock state. When we will say process is in deadlock state, when process never changes its state that state is waiting state okay. Now we have different types of resources in the system and that resources are physical resources and logical resources. So how deadlock will occur in the system when we have same resource type that we will see. Now consider a situation that we have three type drives and we have three processes. So here three type drive means what we have only one resource that is type drive and there are three instance of this type drive okay. So that's why it is called as the same resource type. So we have a resource type type drive and we have three instance of that resource type. Now we have three processes so consider a situation that process p1 is already using type drive 1, p2 is already using type drive 2, p3 is already using type drive 3. So all three processes are allocated to all three instance of the resources. Now suppose process p1 make request for type drive 2, p2 make request for type drive 3 and p3 make request for type drive 1. Now as you can see here p1 is requesting type drive 2 which is already held by p2, p2 is requesting type drive 3 which is already held by p3 and p3 is requesting type drive 1 which is already held by p1. So what will happen all these processes will enter in waiting state and once they enter into waiting state they will never release their resources which is held by them okay. So these processes enter into the waiting state and they will never change their waiting state. So this situation is called as a deadlock state and we can say that all processes p1, p2, p3 are in waiting state okay. Next now we have now we can right now we studied the example of same resource type. Now we are saying whenever we have a different resource type how deadlock will occur in the system. So for different resource type consider a system model which have two resources. Now we are saying we have two resources that is type drive and printer and we have two processes. So suppose here process p1 is already using type drive and p2 is already using printer. So p1 now request for printer which is already used by p2 and p2 request for type drive which is already used by p1. Now again the same thing p1 request this resource but as this resource is already held by p2 p1 will enter in waiting state. Similarly p2 request for type drive and as it is held by p1 between enters in waiting state and both p1 and p2 enter in waiting state then they will never release type drive 1 and printer and these two processes never get their requested resource. So automatically system enters in deadlock state. So this is how deadlock occurs in the system whenever all processes in the system enters into the waiting state and they are waiting for each other and all processes are in waiting state so they never change their waiting state and system cannot perform any fruitful task and that situation is called as a deadlock situation or deadlock state and the processes which are in waiting state we can say that that processes are in deadlock state okay. So this is how the deadlock can occur in the system. So these are the references thank you.