Deadlock Flashcards

1
Q

What’s the definition of a deadlock?

A

A set of processes is deadlocked if each process in the set is waiting
for an event that only a process in the set can cause

In the context of synchronization, the event is a resource.

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

In a Resource allocation graph what are the 2 types of edges?

A
  1. Request = edge from process to
    resource type
  2. Allocation = edge from resource
    instance to a process
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can we simplify the Resource allocation graph When there’s only one
instance per resource type?

A

By eliminating resources and only marking dependencies between processes.
e.g: P1 requests resource R1 which is held by P2.
so we will just have a directed edge from P1 to P2.

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

What are the 4 Necessary conditions for deadlock?

A

All of these must hold in order for a deadlock to occur:

  1. Mutual exclusion
    • Some resource is (i) used by more than one process, but is
    (ii) exclusively allocated one process at a time (cannot be shared)
    • If used by only one process, or can be shared => can’t deadlock
  2. Hold & wait
    • Processes may hold one resource and wait for another
    • If resources allocated atomically altogether => can’t deadlock
  3. Circular wait
    • P(i) waits for resource held by P((i+1) % n) // some enumeration
    • Otherwise, recursively, there exists one process that need not wait
  4. No resource preemption
    • If resources held can be released (e.g., after some period of time),
    then can break circular wait
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Who is responsible for dealing with deadlocks?

A

– Typically, you (the programmer)

• You need to be aware and do it yourself

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

What are the 2 ways of dealing with deadlocks?

A
  1. Design the system such that it is never allowed to enter into
    a deadlock situation
    – Example: this is how we’ll acquire locks
  2. Allow the system to experience deadlock, but put in
    mechanisms to detect & recover
    – Example: memory exhaustion
    => kill random process
    (or write it to disk and leave it there for a long while)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What’s deadlock prevention?

A

violate 1 of the 4 conditions

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

How can we detect a deadlock?

A

If there’s only one instance of each resource type
– Search for a cycle in the (simplified) resource allocation graph
• Found  deadlock

In the general case, which allows multiple instances per type
– Necessary conditions for deadlock != sufficient conditions for deadlock
– A graph can have a cycle while the system is not deadlocked
- Still algorithms for detection exist.

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

What’s deadlock avoidance?

A

System stays away from deadlocks by being careful
on a per resource-allocation decision basis

Bankers algorithm.

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

How the bankers algorithm works?

A

Banker’s data structure
– max[p] = (m_1,m_2, …, m_k) = max resource requirements for process p
– cur[p] = (c_1,c_2, …, c_k) = current resource allocation for process p
– R = (r_1, r_2, …, r_k) = the current resource request (for process p)
– avail = (a_1, a_2, …., a_k) = currently available (free) resources (global)

Tentatively assume that request R was granted
– cur[q] += R // vector addition
– avail -= R // vector subtraction

• Check if “safe state” (= can satisfy all processes in some order)
– initialize P to hold all non-terminated process
– while( P isn’t empty ) {
found = false
for each p in P { // find one p that can be satisfied
if( max[p] – cur[p] <= avail ) // p’s biggest request
avail += cur[p] // pretend p terminates
P -= {p}
found = true
}
if( ! found ) return FAILURE
}
return SUCCESS

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

What’s a safe state in the bankers algorithm?

A

A state whereby we’re sure that all processes can be executed, in a
certain order, one after the other, such that each will obtain all the
resources it needs to complete its execution

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

Thus the bankers algorithms is conservative?

A

Yes. as there’s a possibility for no

deadlock even if allocation is made, but OS doesn’t take that chance

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

What’s the time complexity of the bankers algo?

A

O(n^2)
– Even though number of possible orders is n!
– Since resources increase monotonically as processes terminate
– As long as it’s possible to execute any set of processes
• Execution order not important
• (There is never any need to backtrack and try another order)

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