Necessary Conditions: · unsharable resources · hold while waiting · circular wait · no preemption Unsharable Resources - resources that may be used exclusively only; that is, with no other combination or sharing of resources. e.g. magnetic tape, printer Hold While Waiting - when process is allowed to hold resources while requesting other resources. e.g. process A holds R1 and R2, while it request R3 and R4 Circular Wait - a state in which a cycle of processes exists such that each process holds a resource that is being requested by the next process in the cycle and that request has been refused. e.g. process A holds R1 and R2, while it request R3 and R4 which may be held by process B which is requesting R1 No Preemption - resources cannot be recovered from processes. e.g. process A holds R1, and R1 cannot be recovered Therefore, for deadlock to occur all of the four conditions must take place in the system.
To prevent deadlock incidents, at least one of the four necessary conditions should be removed. Unsharable Resources Unsharable resources may be identified as printers, plotter, and magnetic tapes in which case cannot share resources. However, simple modifications to the handling nature of such devices will at least make these unsharable resources virtually sharable. A good example would be the implementation of a printer spooler. The spooler will print the output, which were stored in temporary files, as deterined by the managing policy of the printing queue. Thus, a few processes may print simultaneously on the same virtual printer. Hold While Waiting There are two dominant manners in which the hold while waiting condition may be avoided. The first requires that each process will have to specify and acquire all resources needed at one time. If this is not possible, the process will wait until all necessary resources are available for use. The second states that the process will have to release its held resources beofre requesting another. Note that both of these methods significantly decrease resource utilization. Circular Wait The algorithm used as a remedy to the circular wait problem basically numbers resources and order them into increasing sequence. Processes may have resource requests granted only if it holds resources with a lower number or priority than that of the last requested one. Therefore, a circle is never allowed to form. No Preemption To prevent no preemption, the OS must allow some form of preemption. Preemption of resources of a certain process will force the process to be rolled back to the point at which it acquired it.
This approach is based upon constant periodic system inspection for the deadlock state. Depending on system overhead, the approaches for detection will vary based upon time intervals of system inspection. Once detected, there are two possible recovery methods: process tremination and resource preemption. Process termination or abortion is a very risky recovery method. Depending upon the resources that a process is using and when it is terminated will drastically affect the system. In some cases, all processes may be aborted and the system starts of clean. Resource preemption - to terminate one process at a time calls for some type of victim selection. This may be based upon process or resource priority and time consumption. Keep in mind that starvation must be avoided when selecting termination victims. Never consider the ostrich algorithm in which case the system is suppose to pretend that the problem of deadlock does not exist. This approach does not seem very logical, but the reason for this is that the price for handling deadlocks may be extremely high with low probablity of occurrence. Therefore, the deadlock problems are handed over to the system operator or the user.
Deadlock avoidance tries to avoid the deadlock state instead of coping with the prevention or recovery methods of deadlock. In such cases, the OS may pretend that the request is granted, and then run a deadlock pdetection procedure. So, if deadlock is detected by the simulator, then the process is not allowed to continue and is rolled back. However, this approach does not completely remove the possibility of deadlock. A better approach would be to make each process pronounce the maximum number of resources of each type that it may need. Then, it is dynamically investigated by a detection algorithm to guarantee it. However, these avoidance methods have a very high overhead, and this may out weigh its usefullness.
Rectangles represent different resource types and circles represent
processes. Dark edges directed from resource to a process states that process
holds that resource. Light edge directed from a process to a resource states
that a process requests a resource of that type.
Process P holds the only instance of resource type R1, while requesting
resource of type R2.
Process
Q holds resource of type R3, while requesting resources of type R1 and
R2. Process P holds the resource of type R1, while requesting resource
of type R2.
Problem 1)Are all of the necessary conditions for deadlock independent, or does one or more of them have to hold for another to hold? Explain your answer. 2)Is it possible to have a deadlock involving only one single process? Explain your answer. Answer 1)Hold and wait implies mutual exclusion; circular wait inplies mutual exclusion, hold and wait and no preemption. 2)No. This follows directly from the hold and wait condition.