Lecture 14: Deadlocks Flashcards

1
Q

Deadlock Can Arise if the Following 4 Conditions Hold:

A

Deadlock Can Arise if the Following 4 Conditions Hold:

  1. No Preemption: resources only released by process voluntarily when finished using
    e. g., none of G, M, or K will give up the spots they have
  2. Mutual Exclusion: only 1 process can use a resource at a time
    e. g., only 1 car can use given spot at a time
  3. Hold & Wait: process holding 1+ resources is waiting to acquire others held by other process
    e. g., each car has some of the spots it needs but is waiting for others
  4. Circular Wait: exists a set of waiting processes, {P0, …, Pn} s.t. P0 waits for P1 waits for … waits for Pn waits for P0
    e. g., G waits for M waits for K waits for G
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Deadlock:

A

“Deadlock: Both threads blocked waiting for other to finish

• possible with any synchronization approach involving locking (semaphores, monitors, …)

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

Assumed Model

A

“• Resource types: R1, R2, …, Rm
(CPU cycles, memory space, I/O devices, locks, …)
• Each resource type, Ri, has Wi, instances
• Each process utilizes a resource as follows:
1. Request the resource – if not granted wait until acquired
2. Use the resource
3. Release the resource
• System table recording records if a resource is free or not, process it allocated, and queue of processes waiting for each resource”

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

” Resource Allocation Graph: “

A

“V = Set of vertices
E = Set of edges
1. Request Edge: Pi -> Rj
2. Assignment Edge: Rj -> Pi”
“P = {P1,” “…, Pn}:” “processes in system”
“R = {R1,” “…, Rm}:” “resource types in system”

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

Interpretation:

A

“• No cycles Þ no deadlock
• Cycle and n instances per resource type Þ possible deadlock
• Cycle and 1 instance per resource type Þ deadlock”

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

Prevention

A

”= breaking one of the conditions above”

…well, except for mutual exclusion

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

” Hold & Wait: “

A

“Defined: Process holding a resource waiting to acquire
others held by other process
Breaking? Ensure that when process requests resource, does not hold another resource
• require process to request & be allocated all its resources before begins execution
• poor resource utilization, starvation is possible”

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

” No Preemption: “

A

“Defined: Resources only released voluntarily
Breaking? If process holding resources requests another it can’t get, must release all
• released resources added to those processes waiting for them
• process only restarts when it can get old and requested resources are available”

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

” Deadlock Prevention “

A

” Remove one of the 4 preconditions for deadlock

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

Deadlock Avoidance:

A

“• Similar to Deadlock Prevention
à stops deadlock before it occurs
• Unlike deadlock prevention, does not prevent one of the 4 deadlock conditions
instead: monitors the system (resource requests, holds, releases) continuously
disallows requests that lead to “unsafe states”
Unsafe state: Deadlock may occur Safe state: Deadlock won’t occur”

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

Safe States:

A

“1. Safe state = no deadlock

  1. Unsafe state = danger of deadlock
  2. Avoidance = never enter an unsafe state”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Banker’s Algorithm

A

“Banker’s Algorithm: A Deadlock Avoidance Algorithm
• taken from approach used by banks to deal with credit lines
à to grant credit, must guarantee that every customer can have credit lines met by available funds
à can delay granting credit or refuse to grant some credit requests
à may delay to wait for another customer to repay”

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

” Deadlock Detection “

A

“Allow system to enter deadlocked state
Periodically run deadlock detection algorithm
If deadlock detected, run recovery scheme to break”

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

” Cost: “

A

“O (m n2)
• n = number of processes
• m = number of resources
Expensive!!! Therefore, don’t run after every resource allocation”
“Frequency of Running Detection?
Many factors:
1. How often system deadlock is likely to occur
2. How many processes will need to be rolled back? (One per disjoint cycle)”

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

Once Deadlock Discovered, Then What?

A
"A:    Process termination
1.    Kill all deadlocked processes
2.    Kill 1 process at a time until deadlock cycle is eliminated
In what order?
      1.  Based on priority
      2.  Based on completion percentage
      3.  Based on resources held
     4.  Based on resources requested
     5.  Interactive vs. Batch"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

“Another Option: Preempt Resources “

A

“• Select victim process
• Rollback process to some safe state (undo effects). Restart process for that state
Danger of starvation”

17
Q

Ostrich Method

A

Pretend there are no deadlocks and allow users to handle them
• Most OS (including UNIX, Windows)
• JVM