This preview shows page 14 - 23 out of 40 pages.
Deadlock is a situation where a process or a set of processes is blocked, waiting for some other resource that is held by some other waiting process. It is an undesirable state of the system. The following are the four conditions that must hold simultaneously for a deadlock to occur.
Methods of handling deadlocks : There are three approaches to deal with deadlocks. 1. Deadlock Prevention 2. Deadlock avoidance 3. Deadlock detectionThese are explained as following below. 1. Deadlock Prevention : The strategy of deadlock prevention is to design the system in such a way that the possibility of deadlock is excluded. Indirect method prevent the occurrence of one of three necessary condition of deadlock i.e., mutual exclusion, no pre-emption and hold and wait. Direct method prevent the occurrence of circular wait. Prevention techniques – Mutual exclusion – is supported by the OS. Hold and Wait – condition can be prevented by requiring that a process requests all its required resources at one time and blocking the process until all of its requests can be granted at a same time simultaneously. But this prevention does not yield good result because :
No pre-emption – techniques for ‘no pre-emption are’
Circular wait One way to ensure that this condition never hold is to impose a total ordering of all resource types and to require that each process requests resource in an increasing order of enumeration, i.e., if a process has been allocated resources of type R, then it may subsequently request only those resources of types following R in ordering. 2. Deadlock Avoidance : This approach allows the three necessary conditions of deadlock but makes judicious choices to assure that deadlock point is never reached. It allows more concurrency than avoidance detection A decision is made dynamically whether the current resource allocation request will, if granted, potentially lead to deadlock. It requires the knowledge of future process requests. Two techniques to avoid deadlock :
Advantages of deadlock avoidance techniques :
Disadvantages :
3. Deadlock Detection : Deadlock detection is used by employing an algorithm that tracks the circular waiting and killing one or more processes so that deadlock is removed. The system state is examined periodically to determine if a set of processes is deadlocked. A deadlock is resolved by aborting and restarting a process, relinquishing all the resources that the process held.
Article Tags : Practice Tags :
Deadlock Characteristics As discussed in the previous post, deadlock has following characteristics.
Deadlock Prevention We can prevent Deadlock by eliminating any of the above four conditions. Eliminate Mutual Exclusion Eliminate Hold and wait
Eliminate No Preemption Eliminate Circular Wait Each resource will be assigned with a numerical number. A process can request the resources increasing/decreasing. order of numbering. For Example, if P1 process is allocated R5 resources, now next time if P1 ask for R4, R3 lesser than R5 such request will not be granted, only request for resources more than R5 will be granted. Deadlock Avoidance Banker’s Algorithm Inputs to Banker’s Algorithm:
The request will only be granted under the below condition:
Example: Total resources in system: A B C D 6 5 7 6Available system resources are: A B C D 3 1 1 2Processes (currently allocated resources): A B C D P1 1 2 2 1 P2 1 0 3 3 P3 1 2 1 0Processes (maximum resources): A B C D P1 3 3 2 2 P2 1 2 3 4 P3 1 3 5 0Need = maximum resources - currently allocated resources. Processes (need resources): A B C D P1 2 1 0 1 P2 0 2 0 1 P3 0 1 4 0Note: Deadlock prevention is more strict than Deadlock Avoidance. Article Tags : Practice Tags : a priori
|