Deadlocks: Model For Multiprogramming and Resource Sharing
Deadlocks: Model For Multiprogramming and Resource Sharing
System Model
• Our discussion of deadlock uses a specific system
model for multiprogramming and resource sharing
However, other types of resources, such as printers, just can’t be shared, so it’s impossible
to eliminate mutual exclusion totally
If a request is granted, then the request edge changes into an assignment edge; finally,
when the process is done with a resource, the assignment edge returns to a claim edge
Max — A matrix that tracks the maximum need of each process for each resource type
Allocation — A matrix that tracks the number of instances of each resource type that is
currently used by each process
Need — A matrix that indicates how many more of each resource type are needed by
each process; note that Need[i][j] = Max[i][j] – Allocation[i][j]
Choices range from invoking the algorithm for every resource request (expensive, but
should catch the “first” process that gets deadlocked) to less frequent heuristic rules like
once every t units of time or whenever CPU utilization drops below some threshold
Deadlock Recovery
• Once deadlock is detected, recovery must then take
place; an easy option is to “tell a human” via system
logs or messages — let the person deal with it
How should the process handle the loss of the resource? Since the process can’t proceed
without the resource, it may need to be rolled back — but to where? Worst case: total
rollback by restarting the process
How can we avoid starvation? If we’re not careful, the same process may always be picked
as the victim whenever deadlock is detected, and so it never completes