Lecture 6 - Deadlocks Flashcards

1
Q

Define a Deadlock

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Is there an efficient solution to the deadlock problem?

A

Not in the general case.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are 4 classes of resource classification?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which classes of resources are prone to deadlocks?

A

reusable and non-preemptable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the 4 necessary conditions for deadlocks to be possible?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

For deadlocks to occur, can a process to be reset to an earlier state where resources were not held?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which of the necessary conditions for deadlocks do these statements breach?

  1. Systems with only shared resources cannot deadlock.
  2. Systems that abort processes which request a resource that is in use.
  3. Preemptions may be possible if a process does not use its resources until it has acquired all it needs.
  4. Systems that detect or avoid deadlocks.
  5. Transaction processing systems provide checkpoints so that processes may back out of a transaction.
A
  1. Mutual exclusion
  2. Hold and wait
  3. No preemption
  4. Prevents cycle
  5. Irreversible process
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Is a cycle in a resource graph sufficient with multiple unit resources? Why or why not?

A

No, A knot must exist—a cycle with no non-cycle outgoing path from any involved node.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What’s a resource graph knot?

A

A cycle with no non-cycle outgoing path from any involved node.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the 4 general strategies used for dealing with deadlocks

A
  1. Ignorance: pretend there is no problem at all.
  2. Prevention: design a system in such a way deadlock is excluded a priori.
  3. Avoidance: make a decision dynamically checking whether a request will, if granted, potentially lead to a deadlock or not.
  4. Detection: let the deadlock occur and detect when it happens, and take some action to recover after the fact.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What’s the difference between how Mathematicians and Engineers deal with deadlocks?

How does UNIX deal with it? Why?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the 2 methods by which deadlock prevention is done?

A

Indirect methods –prevent the occurrence of one of the necessary conditions listed earlier.
Direct methods –prevent the occurrence of a circular wait condition.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Why do we say that deadlock prevention strategies are “conservative”?

A

Because we solve the problem of deadlock by limiting access to resources and by imposing restrictions on processes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How does deadlock prevention deal with each of the 4 necessary conditions for deadlocks?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the 3 approaches to Deadlock avoidance? What do these methods require?

A
  1. Resources trajectories
  2. Safe/unsafe states
  3. Dijkstra’s Banker’s algorithm

Requires that the system has some additional a priori information available.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What’s the simplest and most useful model for deadlock avoidance?

A

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

17
Q

Define a Safe State. When is a system in a safe state?

A

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

18
Q

Can a deadlock occur if a system is in safe state?

A

No

19
Q

Does a system in an unsafe state guarantee a deadlock?

A

No, only the possibly of one

20
Q

How does deadlock avoidance deal with safe states?

A

It makes sure that the system is never in an unsafe state.

21
Q

What methods do avoidance algorithms use for single instance of a resource type? What about multiple instances of resource type?

A
  1. Use a resource allocation graph: Resources must be claimed a priori in the system
  2. Use the Banker’s algorithm
22
Q

Whats the difference between a Claim edge and a Request edge in a Resource-Allocation Graph

A

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.

23
Q

Explain the Banker’s algorithm

A
  • 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
24
Q

Define the formula for NEEDij in Banker’s algorithm.

A

NEEDij= MAXij-HOLDij, for all i & j

25
Q

What does the AVAILj represent in Banker’s algorithm?

A

it represents units of each resource (initialized to maximum, changes dynamically).

26
Q

What are the 3 steps to resource request REQj by a process Pi in Banker’s algorithm?

A

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
27
Q

How does the deadlock detection method deal with deadlocks?

A

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

28
Q

What’s the advantages and disadvantages of deadlock detection for each resource request?

A

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

29
Q

What are the 3 methods to recover from a deadlock

A

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.

30
Q

for Deadlock Detection, name the:

  1. Resource Allocation Strategy
  2. Different Schemes
  3. Major Advantages
  4. Major Disadvantages
A
  1. Resource Allocation Strategy
    • Very liberal; grant resources as requested
  2. Different Schemes
    • Invoke periodically to test for deadlock
  3. Major Advantages
    • Never delays process initiation.
    • Facilitates on-line handling
  4. Major Disadvantages
    • Inherent preemption losses
31
Q

for Deadlock Prevention, name the:

  1. Resource Allocation Strategy
  2. Different Schemes
  3. Major Advantages
  4. Major Disadvantages
A
  1. Resource Allocation Strategy
    • Conservative; under-commits resources
  2. Different Schemes
    • Requesting all resources at once
    • Preemption
    • Resource ordering
  3. 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.
32
Q

for Deadlock Avoidance, name the:

  1. Resource Allocation Strategy
  2. Different Schemes
  3. Major Advantages
  4. Major Disadvantages
A
  1. Resource Allocation Strategy
    • Selects midway between that of detection and prevention
  2. Different Schemes
    • Manipulate to find at least one safe path.
  3. Major Advantages
    • No preemption necessary
  4. Major Disadvantages
    • Future resource requirements must be known.
    • Processes can be blocked for long periods.
33
Q

Write down Banker algorithm’s”isSafe” method

A

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

34
Q
Define the states:
Very safe
Safe
Unsafe
Deadlock
in terms of NEEDi and AVAIL of Pi
A

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.

35
Q

Define a Resource Allocation State

A

Resource-allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes