Introduction to Deadlock - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

Introduction to Deadlock

Description:

... Remember Dining Philosophers? Dining Philosopher Challenge ... Cars in intersection. Necessary and Sufficient Conditions for Deadlock. Mutual exclusion ... – PowerPoint PPT presentation

Number of Views:314
Avg rating:3.0/5.0
Slides: 31
Provided by: csU70
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Deadlock


1
Introduction to Deadlock
  • Lecture 21
  • Klara Nahrstedt

2
CS241 Administrative
  • Read Stallings Chapter 6

3
Content of This Lecture
  • Goals
  • Understanding deadlock
  • How to avoid deadlocks
  • Things covered in this lecture
  • Deadlock concepts
  • Deadlock conditions

4
Resource (1)
  • A resource is a commodity needed by a process.
  • Resources can be either
  • serially reusable e.g., CPU, memory, disk space,
    I/O devices, files. acquire ? use ? release
  • Real life analogy?
  • consumable produced by a process, needed by a
    process e.g., messages, buffers of information,
    interrupts. create ? acquire ? use Resource
    ceases to exist after it has been used, so it is
    not released.
  • Real life analogy?

5
Resource (2)
  • Resources can also be either
  • preemptible e.g., CPU, central memory
  • What does it mean?
  • non-preemptible e.g., tape drives.
  • Any other examples?
  • And resources can be either
  • shared among several processes or
  • dedicated exclusively to a single process.

6
Using Semaphore to Share Resource
Process Q() A.Down() B.Down() use
both resource B.Up() A.Up()
Process P() A.Down() B.Down() use
both resource B.Up() A.Up()
Is it OK?
7
But Deadlock can Happen!
Process Q() B.Down() A.Down() use
both resources A.Up() B.Up()
Process P() A.Down() B.Down() use
both resources B.Up() A.Up()
DEADLOCK
8
Deadlock
Mechanism for Deadlock Control
9
Another Example - Remember Dining Philosophers?
10
Dining Philosopher Challenge
  • Think Eat
  • N Philosophers circular table with N chopsticks
  • To eat the Philosopher must first pickup two
    chopsticks
  • ith Philosopher needs ith i1th chopstick
  • Only put down chopstick when Philosopher has
    finished eating
  • Devise a solution which satisfies mutual
    exclusion but avoids starvation and deadlock

11
Seems simple enough ?
  • while(true)
  • think()
  • sem_wait(chopsticki)
  • sem_wait(chopstick(i1) N)
  • eat()
  • sem_post(chopstick(i1) N)
  • sem_post(chopsticki)

12
Deadlock (Each P. holds left fork)
  • while(true)
  • think()
  • sem_wait(chopsticki)
  • sem_wait(chopstick(i1) N)
  • eat()
  • sem_post(chopstick(i1) N)
  • sem_post(chopsticki)

13
Deadlock Definition
  • What is a deadlock?
  • A process is deadlocked if it is waiting for an
    event that will never occur.
  • Typically, but not necessarily, more than one
    process will be involved together in a deadlock
    (the deadly embrace).
  • Is deadlock the same as starvation (or
    indefinitely postponed)?
  • A process is indefinitely postponed if it is
    delayed repeatedly over a long period of time
    while the attention of the system is given to
    other processes. I.e., logically the process may
    proceed but the system never gives it the CPU.

14
Conditions for Deadlock
  • What conditions should exist in order to lead to
    a deadlock
  • Real life analogy such as
  • You take the monitor, I grab the keyboard
  • Cars in intersection

15
Necessary and Sufficient Conditions for Deadlock
  • Mutual exclusion
  • Processes claim exclusive control of the
    resources they require
  • Wait-for condition
  • Processes hold resources already allocated to
    them while waiting for additional resources
  • No preemption condition
  • Resources cannot be removed from the processes
    holding them until used to completion
  • Circular wait condition
  • A circular chain of processes exists in which
    each process holds one or more resources that are
    requested by the next process in the chain

16
Mutual Exclusion
  • Processes claim exclusive control of the
    resources they require
  • How to break it?

17
Wait-for Condition
  • Processes hold resources already allocated to
    them while waiting for additional resources
  • How to break it?

18
(No Transcript)
19
No Preemption Condition
  • Resources cannot be removed from the processes
    holding them until used to completion
  • How to break it?

20
Its difficult to take a tape drive away from a
process that is busy writing a tape
21
Circular Wait Condition
  • A circular chain of processes exists in which
    each process holds one or more resources that are
    requested by the next process in the chain
  • How to break it?

22
(No Transcript)
23
Deadlock Modeling (1)
  • Resource allocation graph
  • Graph have two kinds of nodes
  • Processes
  • Resources
  • Graphs arcs have two meanings
  • Arc from resource node to process node process
    holds resource (i.e., resource has been assigned
    to process and process is holding it)
  • Arc from process node to resource node process
    requests resource (i.e., process is currently
    blocked waiting for that resource)

24
Deadlock Modeling (2)
  • Modeled with directed graphs
  • resource R assigned to process A
  • process B is requesting/waiting for resource S
  • process C and D are in deadlock over resources T
    and U

assign
request
25
Deadlock Modeling (3)
A B
C
  • How deadlock occurs

26
Deadlock Modeling (4)
(o) (p)
(q)
  • How deadlock can be avoided

27
Resource Allocation Graph(multiple resource
types)
28
Deadlock Model
29
Strategies
  • Strategies for dealing with Deadlocks
  • detection and recovery
  • dynamic avoidance
  • careful resource allocation
  • prevention
  • negating one of the four necessary conditions

30
Summary
  • Principles of Deadlock
  • Examples of Deadlock
  • Deadlock Conditions
  • Deadlock Modeling
Write a Comment
User Comments (0)
About PowerShow.com