Deadlock Flashcards
Deadlock
A deadlock involves processes waiting for each other, resulting in a complete halt where processes enter an infinitely waiting state waiting for each other
Livelock
Is a situation where a request for an exclusive lock is denied repeatedly
* Hence, causing starvation
Deadlock Characterization
Deadlock can arise if four conditions hold simultaneously:
* Mutual exclusion: only one process at a time can use a resource
* Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes
* Circular wait: there exists a set {P0 ,P1, …, Pn } of waiting processes such that P0 is waiting for a resource that is held by P1 , P1 is waiting for a resource that is held by P2 , …, Pn–1 is waiting for a resource that is held by Pn , and Pn is waiting for a resource that is held by P0.
* No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task
Resource-Allocation Graph
A set of vertices V and a set of edges E.
V is partitioned into two types:
* P = {P1, P2 , …, Pn }, the set consisting of all the processes in the system
* R = {R1 , R2 , …, Rm}, the set consisting of all resource types in the system
* request edge – directed edge Pi -> Rj
* assignment edge – directed edge Rj ->Pi
Deadlock Prevention
Make sure to prevent one of the four causes of the deadlock
Deadlock Prevention by Mutual Exclusion
Sharable resources
Deadlock Prevention by Hold and Wait
Must guarantee that whenever a process requests a resource, it does not hold any other resources
Deadlock Prevention by Preemption
Use time quantum method
Deadlock Prevention by Circular Wait
Impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration
Deadlock Avoidance
Requires that the system has some additional a priori information available.
* Requires that each process declare the maximum number of resources of each type that it may need
* The deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that there can never be a circular-wait condition
* Resource-allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes
Safe state
– System is in safe state if there exists a sequence <P1 , P2 , …, Pn> of ALL the processes in the systems such that for each Pi , the resources that Pi can still request can be satisfied by currently available resources + resources held by all the Pj, with j < I
– That is:
* If Pi resource needs are not immediately available, then Pi can wait until all Pj have finished
* When Pj is finished, Pi can obtain needed resources, execute, return allocated resources, and terminate
* When Pi terminates, Pi +1 can obtain its needed resources, and so on
Resource-Allocation Graph Scheme
– Claim edge Pi Rj indicated that process Pj may request resource Rj – represented by a dashed line
– Claim edge converts to request edge when a process requests a resource
– Request edge converted to an assignment edge when the resource is allocated to the process
– When a resource is released by a process, assignment edge reconverts to a claim edge
– Resources must be claimed a priori in the system
Deadlock Detection
For single instance per resource:
- Maintain wait-for graph
- Periodically invoke an algorithm that searches for a cycle in the graph. If there is a cycle, there exists a deadlock
- 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
Recovery from Deadlock: Process Termination
- Abort all deadlocked processes
- Abort one process at a time until the deadlock cycle is eliminated
- In which order should we choose to abort?
1. Priority of the process
2. How long process has computed, and how much longer to completion
3. Resources the process has used
4. Resources process needs to complete
5. How many processes will need to be terminated
6. Is process interactive or batch?
Resource Preemption when Recovery from Deadlock by Termination
- Selecting a victim – minimize cost
- Rollback – return to some safe state, restart process for that state
- Starvation – same process may always be picked as victim, include number of rollback in cost factor