Docsity

Deadlocks: Understanding and Prevention, Assignments of Operating Systems

Partial preview of the text

Download Deadlocks: Understanding and Prevention and more Assignments Operating Systems in PDF only on Docsity!

Chapter 3

Submitted by :-ANOOP RANA

BCA 3rd^ Yr

Deadlocks

Chapter 3 2 Overview  Resources  Why do deadlocks occur?  Dealing with deadlocks  Ignoring them: ostrich algorithm  Detecting & recovering from deadlock  Avoiding deadlock  Preventing deadlock

Chapter 3 4 When do deadlocks happen?  (^) Suppose  (^) Process 1 holds resource A and requests resource B  (^) Process 2 holds B and requests A  (^) Both can be blocked, with neither able to proceed  (^) Deadlocks occur when …  (^) Processes are granted exclusive access to devices or software constructs (resources)  (^) Each deadlocked process needs a resource held by

A

B

B

A

Process 1 (^) Process 2 DEADLOCK!

CS 1550, cs.pitt.edu Chapter 3 5 (originaly modified by Ethan Using resources  Sequence of events required to use a resource 

Request the resource

Use the resource

Release the resource

 Can’t use the resource if request is denied 

Requesting process has options

 (^) Block and wait for resource  (^) Continue (if possible) without it: may be able to use an alternate resource  (^) Process fails with error code 

Some of these may be able to prevent deadlock…

CS 1550, cs.pitt.edu Chapter 3 7 (originaly modified by Ethan Four conditions for deadlock 

Mutual exclusion

 (^) Each resource is assigned to at most one process 

Hold and wait

 (^) A process holding resources can request more resources 

No preemption

 (^) Previously granted resources cannot be forcibly taken away 

Circular wait

 (^) There must be a circular chain of 2 or more processes where each is waiting for a resource held by the next member of the chain

CS 1550, cs.pitt.edu Chapter 3 8 (originaly modified by Ethan Resource allocation graphs R  (^) Resource allocation modeled by directed graphs  (^) Example 1:  (^) Resource R assigned to process A  (^) Example 2:  (^) Process B is requesting / waiting for resource S  (^) Example 3:  (^) Process C holds T, waiting for U  (^) Process D holds U, waiting for T  (^) C and D are in deadlock! A S B U T C D

Graph With A Cycle But No Deadlock

Basic Facts  If graph contains no cycles  no deadlock  If graph contains a cycle   if only one instance per resource type, then deadlock  (^) necessary and sufficient condition  if several instances per resource type, possibility of deadlock  (^) necessary condition