DOC PREVIEW
Duke CPS 110 - Lecture 6

This preview shows page 1-2-3-19-20-39-40-41 out of 41 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 41 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 41 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 41 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 41 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 41 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 41 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 41 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 41 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 41 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

OutlineDealing with DeadlockDealing with Deadlock (cont.)The Zax Deadlock ExampleDeadlock TheorySlide 7Slide 8Slide 9Deadlock Detection AlgorithmDeadlock Detection ExampleSlide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Another ExampleSlide 22Slide 23Slide 24Slide 25Slide 26Consumable ResourcesSlide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Deadlock Detection & RecoveryAvoidance - Banker’s AlgorithmRepresenting the StateBasic Outline of AlgorithmSlide 39Slide 40Slide 41Slide 42OutlineObjective for today: Formal treatment of deadlock.Dealing with DeadlockIt can be prevented by breaking one of the prerequisite conditions (review):–Mutually exclusive use of resources•Example: Allowing shared access to read-only files (readers/writers problem from readers point of view)–circular waiting•Example: Define an ordering on resources and acquire them in order (lower numbered fork first)–hold and wait –no pre-emptionDealing with Deadlock (cont.)Let it happen, then detect it and recover –via externally-imposed preemption of resourcesAvoid dynamically by monitoring resource requests and denying some.–Banker’s Algorithm ...The Zax Deadlock ExampleDeadlock TheoryState of resource allocation captured in Resource Graph–Bipartite graph model with a set P of vertices representing processes and a set R for resources.–Directed edges•RiPj means Ri alloc to Pj•PjRi means Pj requests Ri–Resource vertices contain units of the resourceResource R0Resource R1Process P0Process P1Request ArcAlloc ArcReusable ResourcesDeadlock TheoryState transitions by operations:–Granting a request–Making a new request if all outstanding requests satisfiedDeadlock defined on graph:–Pi is blocked in state S if there is no operation Pi can perform–Pi is deadlocked if it is blocked in all reachable states from S–S is safe if no reachable state is a deadlock state (i.e., having some deadlocked process) Resource R0Resource R1Process P0Process P1Request ArcAlloc ArcDeadlock Theory•Cycle in graph is a necessary condition–no cycle no deadlock.•No deadlock iff graph is completely reducible–Intuition: Analyze graph, asking if deadlock is inevitable from this state by simulating most favorable state transitions.R0 R1P0P1Request ArcAlloc ArcP3The Zax Deadlock ExampleZ0Z1B0B1Deadlock Detection AlgorithmLet U be the set of processes that have yet to be reduced. Initially U = P. Consider only reusable resources.while (there exist un bloc ked processes in U){ Remove unblocked Pi from U; Cancel Pi’s outstanding requests; Release Pi’s allocated resources; /* possibly unblocking other Pk in U */}if ( U != ) signal deadlock;Deadlock Detection ExampleP0R0R2R3R4R1P3P4P2P1Deadlock Detection ExampleP0R0R2R3R4R1P3P4P2P1Deadlock Detection ExampleR0R2R3R4R1P3P4P2P0Deadlock Detection ExampleR0R2R3R4R1P3P4P2P0Deadlock Detection ExampleR0R2R3R4R1P4P2P0Deadlock Detection ExampleP0R0R2R3R4R1P4P2Deadlock Detection ExampleP0R0R2R3R4R1P4Deadlock Detection ExampleP0R0R2R3R4R1P4Deadlock Detection ExampleP0R0R2R3R4R1Deadlock Detection ExampleR0R2R3R4R1Completely ReducibleAnother ExampleR0 R1P0P1Request ArcAlloc ArcP2With and without P2Another ExampleR0 R1P0P1Request ArcAlloc ArcWith and without P2Is there an unblockedprocess to start with?Another ExampleR0 R1P0P1Request ArcAlloc ArcWith and without P2Another ExampleR0 R1P0P1Request ArcAlloc ArcWith and without P2Another ExampleR0 R1P0P1Request ArcAlloc ArcWith and without P2Another ExampleR0 R1P0P1Request ArcAlloc ArcP2With and without P2Is there an unblockedprocess to start with?Consumable Resources•Not a fixed number of units, operations of producing and consuming (e.g. messages)•Ordering matters on applying reductions–Reducing by producer makes “enough” units, P0P1P2Producer Arc Producer ArcR0R1Consumable Resources•Not a fixed number of units, operations of producing and consuming (e.g. messages)•Ordering matters on applying reductions–Reducing by producer makes “enough” units, –Start with P2P0P1P2Producer Arc Producer ArcR0R1Consumable Resources•Not a fixed number of units, operations of producing and consuming (e.g. messages)•Ordering matters on applying reductions–Reducing by producer makes “enough” units, –Start with P2P0P1P2Producer Arc Producer ArcR0R1Not reducibleConsumable Resources•Not a fixed number of units, operations of producing and consuming (e.g. messages)•Ordering matters on applying reductions–Reducing by producer makes “enough” units, –Start with P2P0P1P2Producer Arc Producer ArcR0R1Consumable Resources•Not a fixed number of units, operations of producing and consuming (e.g. messages)•Ordering matters on applying reductions–Reducing by producer makes “enough” units, –Start with P2–Start with P1P0P1P2Producer Arc Producer ArcR0R1Consumable Resources•Not a fixed number of units, operations of producing and consuming (e.g. messages)•Ordering matters on applying reductions–Reducing by producer makes “enough” units, –Start with P1P0P1P2Producer Arc Producer ArcR0R1Consumable Resources•Not a fixed number of units, operations of producing and consuming (e.g. messages)•Ordering matters on applying reductions–Reducing by producer makes “enough” units, –Start with P1P0P1P2Producer Arc Producer ArcR0R1Consumable Resources•Not a fixed number of units, operations of producing and consuming (e.g. messages)•Ordering matters on applying reductions–Reducing by producer makes “enough” units, –Start with P1P0P1P2Producer Arc Producer ArcR0R1ReducibleDeadlock Detection & Recovery•Continuous monitoring and running this algorithm are expensive.•What to do when a deadlock is detected?–Abort deadlocked processes (will result in restarts).–Preempt resources from selected processes, rolling back the victims to a previous state (undoing effects of work that has been done)–Watch out for starvation.Avoidance - Banker’s Algorithm•Each process must declare its maximum claim on each of the resources and may never request beyond that level.•When a process places a request, the Banker decides whether to grant that request according to the following criteria: –“If I grant this request, then there is a run on the bank (everyone requests the


View Full Document

Duke CPS 110 - Lecture 6

Download Lecture 6
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 6 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 6 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?