Lecture 6 - Deadlocks Flashcards
Define a Deadlock
Permanent blocking of a set of processes that compete for system resources.
A set of processes are in a wait state, because each process is waiting for a resource that is held by some other waiting process.
All deadlocks involve conflicting resource needs by two or more processes.
Is there an efficient solution to the deadlock problem?
Not in the general case.
What are 4 classes of resource classification?
Reusable: something that can be safely used by one process at a time and is not depleted by that use. Processes obtain resources that they later release for reuse by others.
Ex: CPU, memory, specific I/O devices, or files
Consumable: These can be created and destroyed. When a resource is acquired by a process, the resource ceases to exist.
Ex: Interrupts, signals, or messages
Preemptable: these can be taken away from the process owning it with no ill effects (needs save/restore).
Ex: memory or CPU.
Non-preemptable: cannot be taken away from its current owner without causing the computation to fail.
Ex: printer or floppy disk.
Which classes of resources are prone to deadlocks?
reusable and non-preemptable
What are the 4 necessary conditions for deadlocks to be possible?
- Mutual exclusion: processes require exclusive control of its resources (not sharing)
- Hold and wait: process may wait for a resource while holding others
- No preemption: process will not give up a resource until it is finished with it
- Circular wait: each process in the chain holds a resource requested by another
For deadlocks to occur, can a process to be reset to an earlier state where resources were not held?
No
Which of the necessary conditions for deadlocks do these statements breach?
- Systems with only shared resources cannot deadlock.
- Systems that abort processes which request a resource that is in use.
- Preemptions may be possible if a process does not use its resources until it has acquired all it needs.
- Systems that detect or avoid deadlocks.
- Transaction processing systems provide checkpoints so that processes may back out of a transaction.
- Mutual exclusion
- Hold and wait
- No preemption
- Prevents cycle
- Irreversible process
Is a cycle in a resource graph sufficient with multiple unit resources? Why or why not?
No, A knot must exist—a cycle with no non-cycle outgoing path from any involved node.
What’s a resource graph knot?
A cycle with no non-cycle outgoing path from any involved node.
What are the 4 general strategies used for dealing with deadlocks
- Ignorance: pretend there is no problem at all.
- Prevention: design a system in such a way deadlock is excluded a priori.
- Avoidance: make a decision dynamically checking whether a request will, if granted, potentially lead to a deadlock or not.
- Detection: let the deadlock occur and detect when it happens, and take some action to recover after the fact.
What’s the difference between how Mathematicians and Engineers deal with deadlocks?
How does UNIX deal with it? Why?
Mathematicians: find deadlock totally unacceptable, and say that it must be prevented at all costs.
Engineers: ask how serious it is, and do not want to pay a penalty in performance and convenience.
UNIX approach:
• ignore the problem
• Prevention price is high –inconvenient restrictions
What are the 2 methods by which deadlock prevention is done?
Indirect methods –prevent the occurrence of one of the necessary conditions listed earlier.
Direct methods –prevent the occurrence of a circular wait condition.
Why do we say that deadlock prevention strategies are “conservative”?
Because we solve the problem of deadlock by limiting access to resources and by imposing restrictions on processes.
How does deadlock prevention deal with each of the 4 necessary conditions for deadlocks?
Mutual exclusion
•In general, this condition cannot be disallowed.
Hold-and-wait
•The hold and-wait condition can be prevented by requiring that a process request all its required resources at one time, and blocking the process until all requests can be granted simultaneously.
No preemption
•One solution is that if a process holding certain resources is denied a further request, that process must release its unused resources and request them again, together with the additional resource.
Circular Wait
•The circular wait condition can be prevented by defining a linear ordering of resource types. If a process has been allocated resources of type R, then it may subsequently request only those resources of types following R in the ordering.
What are the 3 approaches to Deadlock avoidance? What do these methods require?
- Resources trajectories
- Safe/unsafe states
- Dijkstra’s Banker’s algorithm
Requires that the system has some additional a priori information available.
What’s the simplest and most useful model for deadlock avoidance?
Requiring 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
Define a Safe State. When is a system in a safe state?
When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state.
System is in safe stateif there exists a sequence 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, withj < 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
Can a deadlock occur if a system is in safe state?
No
Does a system in an unsafe state guarantee a deadlock?
No, only the possibly of one
How does deadlock avoidance deal with safe states?
It makes sure that the system is never in an unsafe state.
What methods do avoidance algorithms use for single instance of a resource type? What about multiple instances of resource type?
- Use a resource allocation graph: Resources must be claimed a priori in the system
- Use the Banker’s algorithm
Whats the difference between a Claim edge and a Request edge in a Resource-Allocation Graph
Claim (dashed line) isn’t a request, its just a notice that the resource will be claimed by the process. A claim is turned into a request edge (solid) when the process requests, and a allocation (solid reverse) turns into a claim once the process is done.
Explain the Banker’s algorithm
- Used for multiple instances
- Each process must a priori claim maximum use
- When a process requests a resource it may have to wait
- When a process gets all its resources it must return them in a finite amount of time
Define the formula for NEEDij in Banker’s algorithm.
NEEDij= MAXij-HOLDij, for all i & j
What does the AVAILj represent in Banker’s algorithm?
it represents units of each resource (initialized to maximum, changes dynamically).
What are the 3 steps to resource request REQj by a process Pi in Banker’s algorithm?
Step 1: verify that a process matches its needs.
if REQj > NEEDij abort—error, impossible
Step 2: check if the requested amount is available.
if REQj > Availj goto Step 1—Pi must wait
Step 3: Provisional allocation. Availj= Availj-REQj Holdij= Holdij+ REQj Needij= Needij-REQj if isSafe() then grant resources—system is safe else cancel allocation; gotoStep 1—Pimust wait
How does the deadlock detection method deal with deadlocks?
The system detects when this happens, by periodically running an algorithm to detect a circular wait condition, then takes some action to recover after the fact
What’s the advantages and disadvantages of deadlock detection for each resource request?
Advantages
- > it leads to early detection, and
- > the algorithm is relatively simple because it is based on incremental changes to the state of the system.
Disadvantages
->Such frequent checks consume considerable processor time
What are the 3 methods to recover from a deadlock
Recovery through Preemption
In some cases, it may be possible to temporarily take a resource away from its current owner and give it to another.
Recovery through Rollback
If it is known that deadlocks are likely, one can arrange to have processes checkpointed periodically. For example, can undo transactions, thus free locks on database records.
Recovery through Termination
The most trivial way to break a deadlock is to kill one or more processes. One possibility is to kill a process in the cycle. Warning! Irrecoverable losses may occur, even if this is the least advanced process.
for Deadlock Detection, name the:
- Resource Allocation Strategy
- Different Schemes
- Major Advantages
- Major Disadvantages
- Resource Allocation Strategy
• Very liberal; grant resources as requested - Different Schemes
• Invoke periodically to test for deadlock - Major Advantages
• Never delays process initiation.
• Facilitates on-line handling - Major Disadvantages
• Inherent preemption losses
for Deadlock Prevention, name the:
- Resource Allocation Strategy
- Different Schemes
- Major Advantages
- Major Disadvantages
- Resource Allocation Strategy
• Conservative; under-commits resources - Different Schemes
• Requesting all resources at once
• Preemption
• Resource ordering - Major Advantages
• Works well for processes with single burst of activity.
• No preemption is needed
• Convenient when applied to resources whose state can be saved and restored easily
• Feasible to enforce via compile-time checks
• Needs no run-time computation.
4. Major Disadvantages • Inefficient. • Delays process initiation. • Preempts more often then necessary. • Subject to cyclic restart. • Preempts without immediate use. • Disallows incremental resource requests.
for Deadlock Avoidance, name the:
- Resource Allocation Strategy
- Different Schemes
- Major Advantages
- Major Disadvantages
- Resource Allocation Strategy
• Selects midway between that of detection and prevention - Different Schemes
• Manipulate to find at least one safe path. - Major Advantages
• No preemption necessary - Major Disadvantages
• Future resource requirements must be known.
• Processes can be blocked for long periods.
Write down Banker algorithm’s”isSafe” method
Find out whether the system is in a safe state.
Work and Finish are two temporary vectors.
Step 1: initialize.
Workj= Availj for all j;
Finishi = false for all i.
Step 2: find a process Pi such that
Finishi = false and
Needij <= Workj
if no such process, goto Step 4.
Step 3:
Workj= Workj + Holdij
Finishi= true goto Step 2.
Step 4:
if Finishi= true for all i
then return true—yes, thesystem is safe
else returnfalse—no, thesystem is NOT safe
Define the states: Very safe Safe Unsafe Deadlock in terms of NEEDi and AVAIL of Pi
Very safe
NEEDi<= AVAIL for all Processes Pi.
Processes can run to completion in any order.
Safe (but take care)
NEEDi > AVAIL for some Pi
NEEDi <= AVAIL for at least one Pi such that
There is at least one correct order in which the processes may complete their use of resources.
Unsafe (deadlock inevitable)
NEEDi > AVAIL for some Pi
NEEDi <= AVAIL for at least one Pi
But some processes cannot complete successfully.
Deadlock NEEDi > AVAIL for all Pi Processes are already blocked or will become so as they request a resource.
Define a Resource Allocation State
Resource-allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes