 Hello everyone, now today we are going to learn about deadlock prevention mechanism. So, the learning outcome of this session are at the end of this session student will be able to elaborate deadlock prevention mechanism. Recall that we already studied there are 4 necessary conditions for deadlock to occur that is mutual exclusion, hold and wait, no preemption and circular wait. If all these 4 conditions exist simultaneously in the system then deadlock occurs. So, for a deadlock to occur each of the 4 necessary condition must hold in the system. So, by ensuring that at least one of these condition cannot hold we can prevent the occurrence of the deadlock. Now, for prevention of the deadlock what we consider we are considering that one of these conditions should not hold in the system. So, this is the primary assumption for deadlock prevention scheme. So, now we will study in detail all these 4 conditions, but we will consider that this how this 4 condition cannot occur into the system. So, if one of the condition not there in the system then automatically deadlock will never occur in the system. So, first condition is mutual exclusion. Now, as we know for mutual exclusion only one process can access a resource at a time. So, mutual exclusion condition always hold for non-sharable resource. Non-sharable resource means the share the resource which is not shared. So, if that resource is already used by one of the process then other process has to enter in waiting state. But suppose we have a shareable resource that is suppose we have a printer, but still the printer though it is shared by several processes still that printer can print document of only one process at a time. So, the printer cannot be simultaneously shared by several process. So, for printer it is not like that it will print one page for one process another page for another process no once it get the task of first process it finish it and then it take for the next process. So, here there may be the situation that process must wait. But suppose we have a shareable resource for example files which are shared and that files are read only then for that read only files no process will wait automatically whenever that process request for that file it will get access to that file easily. So, for some resources process never wait if the resource is shareable then process never wait. So, process never need to wait for the shareable resource, but sometimes some resources are non-sharable. So, mutual exclusion cannot be prevented just by saying that the all resource make all resources shareable because some of the resources may be non-sharable. So, the assumption for mutual exclusion is that make the resources shareable instead of non-sharable make resources are shareable, but sometimes there is a situation that some resources are non-sharable. So, keep minimum non-sharable resource in the system. This is the first case that is mutual exclusion. Now, the next case that is hold and wait. Now in hold and wait we already studied that hold and wait means process is holding one resource and it make request for another resource. So for this hold and wait as shown here what we are studying deadlock prevention. So for hold and wait this hold and wait situation should never occur into the system. So as shown here if process P wants to request for resource R1 then it cannot hold R2. It has to release R2 first and then request for R1. So there are two different protocols for this hold and wait situation should not be there in the system. First protocol is before process begin its execution that process must request and be allocated all its resources. So first protocol means before execution of the process that process must request all its resources which it requires for its lifetime and that all resources are allocated to the process for the execution. The second protocol is allow a process to request a resource only when it is needed or only when that process has none. For example, initially process P will use resource R2, it use it and it will release that resource then only process P will request for the resource. That is the second protocol and in first protocol the process P must request both R1 and R2 initially and R1 and R2 are allocated to that process that is the first protocol. So just pause the video and consider that there are three processes and that three processes that copies the data from tape drive to disk then from disk file then sorts that disk file and then print the result to the printer. So what will happen in case of protocol 1 and protocol 2? We have only one process and we have three resources tape drive disk file and printer. So how protocol 1 and 2 will be applied here in case of the hold and wait mechanism differentiate both. Let us see we have three resources and one process. So protocol 1 says that before execution of the process P starts allocate all its resources to the process that is allocate all R1, R2, R3 to the process and then process will start it execution and second is what process request the resource only when it has none. So in protocol 1 what will happen all the resources will be allocated to the process but it is unnecessarily holding of the resource for long time. In protocol 2 what will happen there is a sequence first process will request for R1 and R2 then it will use it means first it will read the data from the tape drive and then it will copy to the disk file then it will sort the disk file it will R1 and R2 first it will use for copying the data then it will release both R1 and R2 and then again it will make request for R2 and R3 to sort that disk file and then give it to the printer for printing. So then so this request for R2 and R3 is done after copying the disk file to the printer and then once it use it release it and terminate. So this is how the protocol 1 and 2 can be applied but here there are some disadvantage for this hold and wait. The first is there is low resource utilization now how low resource utilization unnecessarily the all the resources are allocated to the process before it starts its execution. So unnecessarily there is a hold by that process to all its resources. So though other process may request for the resource and that resource is not being used by the currently process then it is wastage of that resource. So resources cannot be utilized properly in case of the first protocol. Only resources may be allocated but they unused for long period of time they remain unused for long period of time. So release type drive and disk file and again request is this is the case in the second protocol that first we are releasing type drive and disk file and again we are requesting disk file instead of that keep disk file as it is only release type drive and the next request is made only for printer. And as it is hold and wait it says that the new request will be made only when process has none that is why we have to release disk file and again we have to request the disk file. So this is how resources are utilized very poorly in case of the hold and wait condition and starvation may occur into the system. Now how starvation will occur? Now suppose the process has long bus time in case of protocol 1 all resources will be allocated to the process and as all resources are allocated to the process the process unnecessarily holding that resource. So the other process which request for the resource may enter in waiting state for long period of time till that process completes its execution. So unnecessarily processes enters into the waiting state and the process which are holding other resource and another process request for the resource that process again enters into the waiting state. So like this processes may enter in waiting state, waiting state, waiting state and their waiting state never gets changed and the starvation situation may occur into the system. Now no preemption we are saying that this no preemption should not hold. This is the third deadlock prevention mechanism that is no preemption. Now no preemption means never primed the resource. For deadlock prevention we are saying that no preemption should not occur into the system. So what we will say as this no preemption does not hold in the system allow preemption, allow resource preemption. So the protocol design for this is as shown here we have process P1. So as we have process P1 it is already using R1, R2 and R3 and one of the instance of the R2 is used by process P3. So already it is using some resource. Now at this point suppose process P1 make request for R4 but that R4 is already used by P2 as it is already used by P2 there is a process P1 will enter into the waiting state because P2 is held by P2 is holding R4. So here R1, R2, R3 are preempted. So the first protocol says that if process request for new resource and that resource is not allocated to that process then primed it all resources which are held by that process. So it has to primed R1, R2, R3 and P1 will starts its execution only when all these resources that is R1, R2, R3 and R4 are available. So the first protocol for no preemption is whenever process make request for new resource and that new resource is not currently available then primed all its allocated resources and process will start its execution only when all the resources are present, all the resources are available and it is given to the process. This is what the protocol 1 for deadlock prevention. So in next video we will see the protocol 2 also. We will continue with deadlock prevention mechanism in next video. Thank you.