Deadlocks in Computer Science: Understanding and Prevention, Study notes of Introduction to Sociology

An in-depth analysis of deadlocks in computer science, including their definition, causes, approaches to detection and prevention, and special cases. Both reusable and consumable resources, examples of deadlocks, and the impact of deadlocks on systems. It also discusses the importance of deadlocks in real-time applications and their potential consequences.

Typology: Study notes

Pre 2010

Uploaded on 09/17/2009

koofers-user-9cv
koofers-user-9cv 🇺🇸

10 documents

1 / 28

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CompSci 143a Spring, 2009 1
6. Deadlocks
6.1 Deadlocks with Reusable and Consumable Resources
6.2 Approaches to the Deadlock Problem
6.3 A System Model
Resource Graphs
State Transitions
Deadlock States and Safe States
6.4 Deadlock Detection
Reduction of Resource Graphs
Special Cases of Deadlock Detection
Deadlock Detection in Distributed Systems
6.5 Recovery from Deadlock
6.6 Dynamic Deadlock Avoidance
Claim Graphs
The Banker’s Algorithm
6.7 Deadlock Prevention
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download Deadlocks in Computer Science: Understanding and Prevention and more Study notes Introduction to Sociology in PDF only on Docsity!

CompSci 143a

Spring, 2009

6. Deadlocks

6.1 Deadlocks with Reusable and Consumable Resources6.2 Approaches to the Deadlock Problem6.3 A System Model

  • Resource Graphs– State Transitions– Deadlock States and Safe States

6.4 Deadlock Detection

  • Reduction of Resource Graphs– Special Cases of Deadlock Detection– Deadlock Detection in Distributed Systems

6.5 Recovery from Deadlock6.6 Dynamic Deadlock Avoidance

  • Claim Graphs– The Banker’s Algorithm

6.7 Deadlock Prevention

CompSci 143a

Spring, 2009

Deadlocks

  • Informal definition: Process is blocked on

resource that will never be released.

  • Deadlocks

waste resources

  • Deadlocks are

rare

  • Many systems ignore them
    • Resolved by explicit user intervention
      • Critical in many real-time applications
        • May cause damage, endanger life

CompSci 143a

Spring, 2009

Examples of Deadlocks

p1: ...

p2: ...

open(f1,w);

open(f2,w);

open(f2,w);

open(f1,w);

...

...

•^

Deadlock when executed concurrently p1: if (C) send(p2,m);

p2: ...

while(1){...

while(1){...

recv(p2,m);

recv(p1,m);

send(p2,m);

send(p1,m);

... }

... }

•^

Deadlock when

C

not true

CompSci 143a

Spring, 2009

Deadlock, Livelock, Starvation

-^

Deadlock:

Processes are blocked

-^

Livelock:

Processes run but make no progress

  • Both deadlock and livelock lead to

starvation

  • Starvation may have other causes
    • ML scheduling where one queue is never empty– Memory requests: unbounded stream of 100MB

requests may starve a 200MB request

CompSci 143a

Spring, 2009

System Model for Deadlock

Detection, Avoidance, etc.

•^

Assumptions:– When a process requests a resource, either the request is

fully granted or the process blocks

  • No partial allocation– A process can only release resources that it holds -^

Resource graph:^ – Vertices are processes, resources, resource units– Edges (directed) represent requests and allocations of

resources

CompSci 143a

Spring, 2009

System Model: Resource Graph

Resource graph:

Process = CircleResource = Rectangle with small circles for each unitRequest = Edge from process to resource classAllocation = Edge from resource unit to process

Figure 6-

CompSci 143a

Spring, 2009

System Model

  • A process is

blocked

in state S if it cannot

request, acquire, or release any resource.

  • A process is

deadlocked

in state S if it is

currently blocked now and remains blockedin all states reachable from state S

  • A state is a

deadlock state

if it contains a

deadlocked process.

  • State S is a

safe state

if no deadlock state

can be reached from S by any sequence ofrequest, acquire, release.

CompSci 143a

Spring, 2009

11

Example

2 processes

p

1

,^

p

; 2 resources 2

R

R

•^

p

1

and

p

2

both need

R

1

and

R

2

•^

p

1

requests

R

1

before

R

2

and releases

R

2

before

R

•^

p

2

requests

R

2

before

R

1

and releases

R

1

before

R

Figure 6-3: Transitions by

p

only 1

CompSci 143a

Spring, 2009

Deadlock Detection

•^

Graph Reduction:

Repeat the following

  1. Select unblocked process

p

  1. Remove

p

and all request and allocation edges

•^

Deadlock

Graph not completely reducible.

•^

All reduction sequences lead to the same result.

Figure 6-

CompSci 143a

Spring, 2009

Special Cases of Detection

-^

Testing for whether a specific process

p

is

deadlocked:

Reduce until

p

is removed or graph irreducible

-^

Continuous detection:

Current state not deadlocked

Next state

T

deadlocked only if:

a.

Operation was a request by

p

and

b.

p

is deadlocked in

T

Try to reduce

T

by

p

CompSci 143a

Spring, 2009

Special Cases of Detection

  • Immediate allocations, continued.

Knot

: A set K of nodes such that

  • Every node in K reachable from any other node in K• No outgoing edges from any node in K
    • Knot in expedient state

Deadlock :

  • Reason:
    • All processes in K must have outstanding requests• Expedient state means requests not satisfiable

(Remove R2->p1: knot R2,p3,R3,p5)(Reverse edge p1->R1): expedient state

CompSci 143a

Spring, 2009

Special Cases of Detection

•^

For single-unit resources, cycle

deadlock

  • Every

p

must have a request edge to

R

  • Every

R

must have an allocation edge to

p

R

is not available and thus

p

is blocked

•^

Wait-For Graph (wfg):

Show only processes

  • Replace

p

R

p

2

by

p

p

2

:^

p

1

waits for

p

Figure 6-

CompSci 143a

Spring, 2009

Detection in Distributed Systems•^

Distributed Approach– Detect cycles using probes.– If process

pi

blocked on

p

, it launches probe j

p

i

pj

  • pj sends probe

pi

pj

p

k^

along all request edges, etc.

  • When probe returns to

pi

, cycle is detected Figure 6-

CompSci 143a

Spring, 2009

Recovery from Deadlock

  • Process termination
    • Kill all processes involved in deadlock; or– Kill one at a time. In what order?
      • By priority: consistent with scheduling• By cost of restart: length of recomputation• By impact on other processes: CS, producer/consumer
        • Resource preemption
          • Direct: Temporarily remove resource (e.g., Memory)– Indirect: Rollback to earlier “checkpoint”