DOC PREVIEW
CORNELL CS 4410 - Lecture Notes

This preview shows page 1-2-15-16-17-32-33 out of 33 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 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 33 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 33 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 33 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 33 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 33 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 33 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Deadlocks: Part II Detection and RecoveryAnnouncementsReview: Dining Philophers ProblemReview: requirements for DeadlockTechniques for Preventing DeadlockTechniques for Preventing Deadlock (con’t)Slide 7Resource Allocation GraphRes. Alloc. Graph ExampleBanker’s Algorithm for Avoiding DeadlockBanker’s AlgorithmBasic AlgorithmSafety CheckBanker’s Algorithm: ExampleSlide 15Slide 16Banker’s Algorithm ExampleRemaining deadlock discussionDeadlock Detection & RecoveryUsing the RAG Algorithm to detect deadlocksResource-Allocation Graph and Wait-for Graph2nd Detection AlgorithmSlide 23ExampleSlide 25Slide 26Slide 27Slide 28When to run Detection Algorithm?Deadlock RecoveryFYI: Java 1.5 Concurrency ToolsSummarySummary (2)Deadlocks: Part IIDetection and RecoveryAnnouncements•Prelim coming up in two and a half weeks:–In class, Thursday, October 16th, 10:10—11:25pm, 1½ hour exam–203 Thurston–Closed book, no calculators/PDAs/…–Bring ID•Topics: Everything up to (and including) Thursday, October 9th–Lectures 1-13, chapters 1-9 (8th ed)•Review Session: TBD•Homework 3 will be available later today3Review: Dining Philophers Problem•Five chopsticks/Five philosophers (really cheap restaurant)–Free-for all: Philosopher will grab any one they can–Need two chopsticks to eat•What if all grab at same time?–Deadlock!•How to prevent deadlock?–Make one of them give up a chopstick (Hah!)–Eventually everyone will get chance to eat•How to avoid deadlock?–Never let philosopher take last chopstick if no philosopher has two chopsticks afterwards4Review: requirements for Deadlock•Mutual exclusion–Only one thread at a time can use a resource.•Hold and wait–Thread holding at least one resource is waiting to acquire additional resources held by other threads•No preemption–Resources are released only voluntarily by the thread holding the resource, after thread is finished with it•Circular wait–There exists a set {T1, …, Tn} of waiting threads•T1 is waiting for a resource that is held by T2•T2 is waiting for a resource that is held by T3•…•Tn is waiting for a resource that is held by T15Techniques for Preventing Deadlock•Infinite resources–Include enough resources so that no one ever runs out of resources. Doesn’t have to be infinite, just large–Give illusion of infinite resources (e.g. virtual memory)–Examples:•Brooklyn bridge with 12,000 lanes. Never wait!•Infinite disk space (not realistic yet?)•No Sharing of resources (totally independent threads)–Not very realistic•Don’t allow waiting –How the phone company avoids deadlock•Call to your Mom in Toledo, works its way through the phone lines, but if blocked get busy signal. –Technique used in Ethernet/some multiprocessor nets•Everyone speaks at once. On collision, back off and retry–Inefficient, since have to keep retrying•Consider: driving to New York City; when hit traffic jam, suddenly you’re transported back home and told to retry!6Techniques for Preventing Deadlock (con’t)•Make all threads request everything they’ll need at the beginning.–Problem: Predicting future is hard, tend to over-estimate resources–Example:•If need 2 chopsticks, request both at same time•Don’t leave home until we know no one is using any intersection between here and where you want to go; only one car on the Bay Bridge at a time•Force all threads to request resources in a particular order preventing any cyclic use of resources–Thus, preventing deadlock–Example (x.P, y.P, z.P,…)•Make tasks request disk, then memory, then…•Keep from deadlock on freeways around SF by requiring everyone to go clockwise7•We saw that you can prevent deadlocks. –By negating one of the four necessary conditions. (which are..?)•We saw that the OS can schedule processes in a careful way so as to avoid deadlocks.–Using a resource allocation graph.–Banker’s algorithm (today).–What are the downsides to these?The story so far..8Resource Allocation Graph•Deadlock can be described using a resource allocation graph, RAG•The RAG consists of:–set of vertices V = P  R, •where P={P1,P2,…,Pn} of processes and R={R1,R2,…,Rm} of resources.–Request edge: directed edge from a process to a resource, •PiRj, implies that Pi has requested Rj.–Assignment edge: directed edge from a resource to a process, •RjPi, implies that Rj has been allocated to Pi.•If the graph has no cycles, deadlock cannot exist. •If the graph has a cycle, deadlock may exist.9Res. Alloc. Graph Example............ .. .R1 R3R3R4R2P3P2P1R1P1 P2 P3P4R2 R4Cycles:P1-R1-P2-R3-P3-R2-P1P2-R3-P3-R2-P2and there is deadlock.Same cycles, but no deadlock10•Toward right idea: –State maximum resource needs in advance–Allow particular thread to proceed if:(available resources - #requested)  max remaining that might be needed by any thread•Banker’s algorithm (less conservative):–Allocate resources dynamically•Evaluate each request and grant if some ordering of threads is still deadlock free afterward •Technique: pretend each request is granted, then run safety algorithm, - Check for ([Maxnode]-[Allocnode] ≤ [Avail])- Grant request if result is deadlock free (conservative!)•Keeps system in a “SAFE” state, i.e. there exists a sequence {P1, P2, … Pn} with P1 requesting all remaining resources, finishing, then T2 requesting all remaining resources, etc..–Algorithm allows the sum of maximum resource needs of all current threads to be greater than total resourcesBanker’s Algorithm for Avoiding Deadlock11Banker’s Algorithm•Decides whether to grant a resource request. •Data structures:n: integer # of processesm: integer # of resourcesavailable[1..m] available[i] is # of avail resources of type imax[1..n,1..m] max demand of each Pi for each Riallocation[1..n,1..m] current allocation of resource Rj to Pineed[1..n,1..m] max # resource Rj that Pi may still requestneedi = maxi - allocationilet request[i] be vector of # of resource Rj Process Pi wants12Basic Algorithm1. If request[i] > need[i] then error (asked for too much)2. If request[i] > available[i] then wait (can’t supply it now)3. Resources are available to satisfy the requestLet’s assume that we satisfy the request. Then we would have:available = available - request[i]allocation[i] = allocation [i] + request[i]need[i] = need [i] - request [i]Now, check if this would leave us


View Full Document

CORNELL CS 4410 - Lecture Notes

Download Lecture Notes
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 Notes 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 Notes 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?