lecture 13 chapter 7 deadlocks
Download
Skip this Video
Download Presentation
Lecture 13 Chapter 7: Deadlocks

Loading in 2 Seconds...

play fullscreen
1 / 21

Lecture 13 Chapter 7: Deadlocks - PowerPoint PPT Presentation


  • 222 Views
  • Uploaded on

Lecture 13 Chapter 7: Deadlocks. Chapter 7: Deadlocks. The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection Recovery from Deadlock . Chapter Objectives.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Lecture 13 Chapter 7: Deadlocks' - Antony


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
chapter 7 deadlocks
Chapter 7: Deadlocks
  • The Deadlock Problem
  • System Model
  • Deadlock Characterization
  • Methods for Handling Deadlocks
  • Deadlock Prevention
  • Deadlock Avoidance
  • Deadlock Detection
  • Recovery from Deadlock
chapter objectives
Chapter Objectives
  • To develop a description of deadlocks,
    • which prevent sets of concurrent processes from completing their tasks
  • To present a number of different methods for preventing or avoiding deadlocks in a computer system
the deadlock problem
The Deadlock Problem
  • A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set
  • Example
    • System has 2 disk drives
    • P1 and P2 each hold one disk drive and each needs another one
  • Example
    • semaphores A and B, initialized to 1

P0P1

wait (A); wait(B)

wait (B); wait(A)

bridge crossing example
Bridge Crossing Example
  • Traffic only in one direction
  • Each section of a bridge can be viewed as a resource
  • If a deadlock occurs, it can be resolved if one car backs up
    • preempt resources and rollback
  • Several cars may have to be backed up if a deadlock occurs
  • Starvation is possible
  • Note : Most OSes do not prevent or deal with deadlocks
slide6

Deadlock Principles

  • A deadlock is a permanent blocking of a set of threads
    • a deadlock can happen while threads/processes are competing for system resources or communicating with each other

Tanenbaum, A. S. (2001)

Modern Operating Systems (2nd Edition).

Illustration of a deadlock

slide7

A required

B required

B required

A required

Deadlock Principles

  • Illustration of a deadlock— scheduling path 1 
    • Q executes everything before P can ever get A
    • when P is ready, resources A and B are free and P can proceed

Happy scheduling 1

slide8

A required

B required

B required

A required

Deadlock Principles

  • Illustration of a deadlock— scheduling path 2 
    • Q gets B and A, then P is scheduled; P wants A but is blocked by A’s mutex; so Q resumes and releases B and A; P can now go

Happy scheduling 2

slide9

A required

B required

deadlock

B required

A required

Deadlock Principles

  • Illustration of a deadlock— scheduling path 3 
    • Q gets only B, then P is scheduled and gets A; now both P and Q are blocked, each waiting for the other to release a resource

Bad scheduling deadlock

slide10

Deadlock Principles

Stallings, W. (2004) Operating Systems:

Internals and Design Principles (5th Edition).

Joint progress diagram

slide11

program design

    • the order of the statements in the code creates the “landscape” of the joint progress diagram
    • this landscape may contain gray “swamp” areas leading to deadlock

swamps

  • scheduling condition
    • the interleaved dynamics of multiple executions traces a “path” in this landscape
    • this path may sink in the swamps

swamps

Deadlock Principles

  • Deadlocks depend on the program and the scheduling
slide12

B required

A required

Deadlock Principles

  • Changing the program changes the landscape
    • here, P releases A before getting B
    • deadlocks between P and Q are not possible anymore

A required

B required

Competing processes

slide13

Deadlock Principles

Joint progress diagram

  • no swamp area: there exists no path leading to deadlock

Stallings, W. (2004) Operating Systems:

Internals and Design Principles (5th Edition).

system model
System Model
  • Resource types R1, R2, . . ., Rm

CPU cycles, memory space, I/O devices

  • Each resource type Ri has Wi instances.
  • Each process utilizes a resource as follows:
    • request
    • use
    • release
deadlock characterization
Deadlock Characterization
  • Mutual exclusion: only one process at a time can use a resource
  • Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes
  • No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task
  • Circular wait: there exists a set {P0, P1, …, P0} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by

P2, …, Pn–1 is waiting for a resource that is held by Pn, and P0 is waiting for a resource that is held by P0.

Deadlock can arise if four conditions hold simultaneously.

resource allocation graph
Resource-Allocation Graph
  • V is partitioned into two types:
    • P = {P1, P2, …, Pn}, the set consisting of all the processes in the system
    • R = {R1, R2, …, Rm}, the set consisting of all resource types in the system
  • request edge – directed edge P1  Rj
  • assignment edge – directed edge Rj Pi

A set of vertices V and a set of edges E.

resource allocation graph cont
Resource-Allocation Graph (Cont.)
  • Process
  • Resource Type with 4 instances
  • Pirequests instance of Rj
  • Pi is holding an instance of Rj

Pi

Rj

Pi

Rj

basic facts
Basic Facts
  • If graph contains no cycles  no deadlock
  • If graph contains a cycle 
    • if only one instance per resource type, then deadlock
    • if several instances per resource type, possibility of deadlock
ad