Chapter Objectives
- To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks.
- To present a number of different methods for preventing or avoiding deadlocks in a computer system.
System Model
Under the normal mode of operation, a process may utilize a resource in only the following sequence:
A set of processes is in a deadlocked state when every process in the set is waiting for an event that can be caused only by another process in the set.
A deadlock situation can arise if the following four conditions hold simultaneously in a system:
A circle in the graph indicates there may be deadlocks.
Generally speaking, we can deal with the deadlock problem in one of three ways:
A deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that a circular- wait condition can never exist. The resource-allocation state is defined by the number of available and allocated resources and the maximum demands of the processes.
A state is safe if the system can allocate resources to each process (up to its maximum) in some order and still avoid a deadlock.
Now suppose that process Pi requests resource Rj. The request can be granted only if converting the request edge Pi → Rj to an assignment edge Rj → Pi does not result in the formation of a cycle in the resource-allocation graph. We check for safety by using a cycle-detection algorithm. An algorithm for detecting a cycle in this graph requires an order of n2 operations, where n is the number of processes in the system.
The resource-allocation-graph algorithm is not applicable to a resource- allocation system with multiple instances of each resource type.
Typically it's 2 steps:
When a process requests resource, pretend to grant the resource and make the modify:
Available = Available - Request[i]
Allocation[i] = Allocation[i] + Request[i]
Need[i] = Need[i] - Request[i]
Use Safety Algorithm to determine the safety of the system.
A deadlock exists in the system if and only if the wait-for graph contains a cycle. To detect deadlocks, the system needs to maintain the wait-for graph and periodically invoke an algorithm that searches for a cycle in the graph. An algorithm to detect a cycle in a graph requires an order of n2 operations, where n is the number of vertices in the graph.
Two ways to eliminate deadlocks by aborting a process:
To eliminate deadlocks using resource preemption, we successively preempt some resources from processes and give these resources to other processes until the deadlock cycle is broken.
3 issues need to be addressed: