Click here to load reader

Modified from Silberschatz, Galvin and Gagne Lecture 13 Chapter 7: Deadlocks

  • View
    227

  • Download
    2

Embed Size (px)

Text of Modified from Silberschatz, Galvin and Gagne Lecture 13 Chapter 7: Deadlocks

  • Slide 1
  • Modified from Silberschatz, Galvin and Gagne Lecture 13 Chapter 7: Deadlocks
  • Slide 2
  • 2 Principles of Computer Operating Systems Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection Recovery from Deadlock
  • Slide 3
  • 3 Principles of Computer Operating Systems 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
  • Slide 4
  • 4 Principles of Computer Operating Systems 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 P 1 and P 2 each hold one disk drive and each needs another one Example semaphores A and B, initialized to 1 P 0 P 1 wait (A);wait(B) wait (B);wait(A)
  • Slide 5
  • 5 Principles of Computer Operating Systems 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
  • Slide 6
  • 6 Principles of Computer Operating Systems Illustration of a deadlock 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). Deadlock Principles
  • Slide 7
  • 7 Principles of Computer Operating Systems Happy scheduling 1 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 Process Q... Get B... Get A... Release B... Release A... A required B required A required Process P... Get A... Get B... Release A... Release B... Deadlock Principles
  • Slide 8
  • 8 Principles of Computer Operating Systems Happy scheduling 2 Illustration of a deadlock scheduling path 2 Q gets B and A, then P is scheduled; P wants A but is blocked by As mutex; so Q resumes and releases B and A; P can now go Process Q... Get B... Get A... Release B... Release A... A required B required A required Process P... Get A... Get B... Release A... Release B... Deadlock Principles
  • Slide 9
  • 9 Principles of Computer Operating Systems Bad scheduling deadlock 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 Process Q... Get B... Get A... Release B... Release A... A required B required A required Process P... Get A... Get B... Release A... Release B... deadlock Deadlock Principles
  • Slide 10
  • 10 Principles of Computer Operating Systems Joint progress diagram Stallings, W. (2004) Operating Systems: Internals and Design Principles (5th Edition). Deadlock Principles
  • Slide 11
  • 11 Principles of Computer Operating Systems Deadlocks depend on the program and the scheduling 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 scheduling condition the interleaved dynamics of multiple executions traces a path in this landscape this path may sink in the swamps Deadlock Principles
  • Slide 12
  • 12 Principles of Computer Operating Systems Competing processes Changing the program changes the landscape here, P releases A before getting B deadlocks between P and Q are not possible anymore Process Q... Get B... Get A... Release B... Release A... A required B required A required Process P... Get A... Release A... Get B... Release B... Deadlock Principles
  • Slide 13
  • 13 Principles of Computer Operating Systems Joint progress diagram no swamp area: there exists no path leading to deadlock Stallings, W. (2004) Operating Systems: Internals and Design Principles (5th Edition). Deadlock Principles
  • Slide 14
  • 14 Principles of Computer Operating Systems System Model Resource types R 1, R 2,..., R m CPU cycles, memory space, I/O devices Each resource type R i has W i instances. Each process utilizes a resource as follows: request use release
  • Slide 15
  • 15 Principles of Computer Operating Systems 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 {P 0, P 1, , P 0 } of waiting processes such that P 0 is waiting for a resource that is held by P 1, P 1 is waiting for a resource that is held by P 2, , P n1 is waiting for a resource that is held by P n, and P 0 is waiting for a resource that is held by P 0. Deadlock can arise if four conditions hold simultaneously.
  • Slide 16
  • 16 Principles of Computer Operating Systems Resource-Allocation Graph V is partitioned into two types: P = {P 1, P 2, , P n }, the set consisting of all the processes in the system R = {R 1, R 2, , R m }, the set consisting of all resource types in the system request edge directed edge P 1 R j assignment edge directed edge R j P i A set of vertices V and a set of edges E.
  • Slide 17
  • 17 Principles of Computer Operating Systems Resource-Allocation Graph (Cont.) Process Resource Type with 4 instances P i requests instance of R j P i is holding an instance of R j PiPi PiPi RjRj RjRj
  • Slide 18
  • 18 Principles of Computer Operating Systems Example of a Resource Allocation Graph
  • Slide 19
  • 19 Principles of Computer Operating Systems Resource Allocation Graph With A Deadlock
  • Slide 20
  • 20 Principles of Computer Operating Systems Graph With A Cycle But No Deadlock
  • Slide 21
  • 21 Principles of Computer Operating Systems 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

Search related