Next: Banker's Algorithm
Up: Deadlock
Previous: Deadlock
  Contents
- no cycle IMPLIES no deadlock
- deadlock IMPLIES cycle (necessary condition)
- cycle IMPLIES maybe deadlock (but not sufficient condition)
- single instance resource AND cycle IMPLIES deadlock
- (necessary and sufficient)
Deadlock: Multiple Instance Resources [112]
DEADLOCK:
NO DEADLOCK:
Methods for Handling Deadlock [113]
- never let deadlock occur
- prevention: break one of the 4 conditions
- avoidance: resources give advance notice of maximum use
- let deadlock occur and do something about it
- detection: search for cycles periodically
- recovery: preempt processes or resources
- don't worry about it (UNIX and other OS)
- cheap: just reboot (it happens rarely)
Deadlock: Prevention [114]
- break mutual exclusion:
- read-only files are shareable
- but some resources are intrinsically nonshareable (printers)
- break hold and wait:
- request all resources in advance
- request (tape, disk, printer)
- release all resources before requesting new batch
- request (tape,disk), release (tape,disk), request (disk,printer)
- disadvantages: low resource utilization, starvation
Deadlock: Prevention [115]
- break no preemption:
- process 1 requests resources already allocated to process 2:
- process 1 forfeits its current resources
- if process 2 is waiting for other resources: process 2 forfeits
- used for resources whose state is easily saved/restored
- CPU registers and memory space
- not printers or tape drives
- break circular wait:
- order all resources by unique numbers (tape drives, etc.)
- processes request resources in increasing order
Deadlock: Avoidance [116]
- processes give advance notice about maximum usage of resources
- processes make actual requests when they need a resource
- avoidance algorithm: allocate request only if it yields a safe state
- a sequence of processes exists such that each process can still get their maximum in sequence
- conceptually the processes could be run in this order
Deadlock: Example of Avoidance [117]
- assume that system has 12 tape drives
| |
maximum needs |
current needs |
| P0 |
10 |
5 |
| P1 |
4 |
2 |
| P2 |
9 |
2 |
| TOTAL |
23 |
9 |
- sequence P1,P0,P2 is a safe sequence
- P2 requests one more tape drive:
| |
maximum needs |
current needs |
| P0 |
10 |
5 |
| P1 |
4 |
2 |
| P2 |
9 |
3 |
| TOTAL |
23 |
10 |
- no safe sequence P1,... because P2 and P0 could deadlock
- for avoidance with multiple instances: use Banker's Algorithm
Avoidance with Single Instances [118]
SAFE:
UNSAFE (P2 requests R2): cycle
Deadlock: Detection [119]
- single instance resource types:
- periodically make a wait for graph
- (just remove resources from the allocation graph)
- check for cycles (n*n)
- multiple instance resource types:
- use a time-varying banker's algorithm
- how often should detection algorithm be run?
- how often is deadlock likely?
- how many processes will be affected?
Deadlock: Recovery [120]
- process termination
- abort all deadlocked processes
- abort one process at a time until cycle eliminated
- run detection algorithm each time
- which process to abort next?
- priority? CPU usage? how many resources?
- resource preemption
- take resources from some processes and give them to others
- select victim: cheapest cost?
- rollback: to safe state and restart
- starvation: deadlock could occur again, process restarts
- include number of rollbacks in cost
Deadlock: Combined Approach [121]
- resources belong to classes
- order the classes hierachically (each gets unique number)
- use appropriate technique within class
- Example of 4 classes:
- internal resources: for PCBs, etc.
- order the resources within the class
- central memory: for a user job
- preemption because a job can always be swapped out
- job resources: for tape drives, etc.
- avoidance because of job-control cards
- swapable space: for user jobs on backing store
- preallocation because maximum requirements known
Next: Banker's Algorithm
Up: Deadlock
Previous: Deadlock
  Contents
Ted Billard
2001-11-17