Wednesday, October 6, 1993 Today: deadlock prevention ------------------------------------------------------------------------------- Recall the four necessary and sufficient conditions for deadlock: - Mutual exclusion - Hold and wait - No preemption - Circular wait Deadlock prevention achieved by ensuring that at least one CANNOT occur ------------------------------------------------------------------------------- Denying "mutual exclusion" - perhaps can substitute a sharable resource for a dedicated one in some cases (e.g., readers' access to a file) - generally not a useful solution because we wish to provide dedicated resources. ------------------------------------------------------------------------------- Denying "hold and wait" - whenever process requests resource it does not hold any other resources. Resource requests granted by system on "all or none" basis - one variant: all resources requested before process begins execution. Cannot proceed until all are granted. - resources may be left idle for long periods of time (resource utilization may be low). Consider program that reads data from tape, computes for long time, writes results to printer. Tape and printer are both held for entire execution time. - another variant: process can request resources if it has none (releases resources before subsequent request). - can improve utilization---previous program can be divided into two phases. Phase one acquires tape drive and disk file. Phase two acquires disk file and printer. - requires greater overhead in system design and also additional execution overhead (to acquire/release resources in intermediate steps) - in either case starvation is possible, especially if process is requesting several popular resources. ------------------------------------------------------------------------------- Denying "no preemption" - If process holding certain resources is denied further request, process must release its original resources and if necessary request them again together with the additional resources. - Alternate formulation: when process requests some resources, check to see if resources are available. If not and if they are assigned to some other waiting process, preempt resources from that other process. Otherwise wait. Process restarting from wait has to reacquire any resources that were preempted during its wait. - Easy to apply to resources whose state can be saved and restored (CPU registers, memory space). More difficult for resources like tape and printers because preempting these resources may cause process to lose work that will then have to be repeated. ------------------------------------------------------------------------------- Denying "circular wait" - Impose total ordering on resource types. Require that each process requests resources in an increasing order of enumeration. - For best efficiency Resource numbers should correspond to expected order of use of resources. If use is out of order results in idle resource (waste) - Large effect on systems programs - change in resource numbers may require change in program - programmer has to be aware of ordering in structuring program - Portability of program compromised - Has been used in number of operating systems including IBM MVS, VAX/VMS ------------------------------------------------------------------------------- Next: Deadlock avoidance Deadlock detection