Operating sytems manages many shared resources (e.g., file, memory, CPUs, status tables, disk drives, messages). Often have many processes competing for limited resources.
Preemptable Resource?????
Model of process action:
request( resource ) use( resource, time ) release( resource )This environment can lead to deadlock when processes need several resources.
Necessary conditions for deadlock (Coffman Conditions):
What to do???????
Ostrich Algorithm (Do Nothing)
Deadlock Detection
Deadlocks are allowed to occur, detected through model checking (FSM), and fixed.
Deadlock Prevention
Prevention depends on ensuring at least one of the four necessary conditions cannot occur:
mutual exclusion | not feasible for many resources. OK for disks, usually not for files. |
---|---|
hold & wait | can preallocate everyting which a process MIGHT require. advantage: easy (mostly) disadvaantage: expensive. Will tie up possibly scarce resources for long periods of time, idle. Can also require require process to release everything anytime it requests something new. Not always feasible. |
no preemption | if a process requests and is blocked, then resources it holds are preempted when required by another process.
Works for processes whose state is easily saved and restored. Does not work well for files. |
circular wait | impose total ordering on resource types, then require processes to only request resources in ascending order. disadvantage: useful ordering often not feasible. Note: If OS uses deadlock prevention (as opposed to avoidance, discussed next) not additional runtime overhead, though process may be needlessly delayed. |
Deadlock Avoidance
Use additinal info about active processes to decide, for example, an ordered list of resource use for each process.
Example: proc 1 will use file 1 then file 2 then release both proc 2 will use file 2 then file 1 then rel. bothThen OS considers each reqest and blocks or allocates based on keeping system in a SAFE state. I.e., given each process useage, a FEASIBLE SEQUENCE exists: some process can complete no matter what, release its resources, which will allow at least one more process to complete no matter what, and so on until all processes have completed).
Banker's Algorithm
Based on knowing the max number of each resource which a process may require.
Algorithm is simple: before granting any new resource request, make sure:
Example:
Alloc Max Avail ABCD ABCD ABCD p0 0012 0012 1520 p1 1000 1750 p2 1354 2356 p3 0632 0654 p4 0014 0656Can all process complete given current resources, max, alloc and avail? I.e. does a feasible sequence exist?
p0 can complete (since Max - Alloc >= Avail), Avail becomes 1532, then p2 can complete, then p3 then p4. No matter what!
Problem with banker's alg. O(mn2) (m resources, n processes). This leads to consideration of deadlock detection algorithms.
Deadlock Recovery
Once deadlock is detected, what next:
Is starvation possible? if you always use the same algorithm to select a victim, will you always tend to select the same victim?
Livelock?
Communications Deadlock
Index | Previous | Next |
---|
Copyright ©2015, G. Hill Price
Send comments to G. Hill Price