DOC PREVIEW
Berkeley COMPSCI 162 - Lecture 10 Deadlock Thread Scheduling

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

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

Unformatted text preview:

CS162 Operating Systems and Systems Programming Lecture 10 Deadlock (cont’d) Thread SchedulingReview: DeadlockReview: Resource Allocation Graph ExamplesReview: Methods for Handling DeadlocksGoals for TodayDeadlock Detection AlgorithmDeadlock Detection Algorithm ExampleWhat to do when detect deadlock?Techniques for Preventing DeadlockTechniques for Preventing Deadlock (con’t)Review: Train Example (Wormhole-Routed Network)Banker’s Algorithm for Preventing DeadlockBanker’s Algorithm ExampleAdministriviaCPU SchedulingScheduling AssumptionsAssumption: CPU BurstsScheduling Policy Goals/CriteriaFirst-Come, First-Served (FCFS) SchedulingFCFS Scheduling (Cont.)Round Robin (RR)Example of RR with Time Quantum = 20Round-Robin DiscussionComparisons between FCFS and Round RobinEarlier Example with Different Time QuantumWhat if we Knew the Future?DiscussionExample to illustrate benefits of SRTFSRTF Example continued:SRTF Further discussionSummary (Deadlock)Summary (Scheduling)CS162Operating Systems andSystems ProgrammingLecture 10Deadlock (cont’d)Thread SchedulingFebruary 18, 2010Ion Stoicahttp://inst.eecs.berkeley.edu/~cs162Lec 10.22/18/10 CS162 ©UCB Fall 2010Review: Deadlock•Starvation vs. Deadlock–Starvation: thread waits indefinitely–Deadlock: circular waiting for resources–DeadlockStarvation, but not other way around•Four conditions for deadlocks–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 threads–Circular wait»There exists a set {T1, …, Tn} of threads with a cyclic waiting patternLec 10.32/18/10 CS162 ©UCB Fall 2010Review: Resource Allocation Graph ExamplesT1T2T3R1R2R3R4Simple ResourceAllocation GraphT1T2T3R1R2R3R4Allocation GraphWith DeadlockT1T2T3R2R1T4Allocation GraphWith Cycle, butNo Deadlock•Recall:–request edge – directed edge T1  Rj–assignment edge – directed edge Rj  TiLec 10.42/18/10 CS162 ©UCB Fall 2010Review: Methods for Handling Deadlocks•Allow system to enter deadlock and then recover–Requires deadlock detection algorithm–Some technique for selectively preempting resources and/or terminating tasks•Ensure that system will never enter a deadlock–Need to monitor all lock acquisitions–Selectively deny those that might lead to deadlock•Ignore the problem and pretend that deadlocks never occur in the system–used by most operating systems, including UNIXLec 10.52/18/10 CS162 ©UCB Fall 2010Goals for Today•Preventing Deadlock•Scheduling Policy goals•Policy Options•Implementation ConsiderationsNote: Some slides and/or pictures in the following areadapted from slides ©2005 Silberschatz, Galvin, and Gagne Note: Some slides and/or pictures in the following areadapted from slides ©2005 Silberschatz, Galvin, and Gagne. Many slides generated from my lecture notes by Kubiatowicz.Lec 10.62/18/10 CS162 ©UCB Fall 2010T1T2T3R2R1T4Deadlock Detection Algorithm•Only one of each type of resource  look for loops•More General Deadlock Detection Algorithm–Let [X] represent an m-ary vector of non-negative integers (quantities of resources of each type):[FreeResources]: Current free resources each type[RequestX]: Current requests from thread X[AllocX]: Current resources held by thread X–See if tasks can eventually terminate on their own[Avail] = [FreeResources] Add all nodes to UNFINISHED do {done = trueForeach node in UNFINISHED {if ([Requestnode] <= [Avail]) {remove node from UNFINISHED[Avail] = [Avail] + [Allocnode]done = false}}} until(done)–Nodes left in UNFINISHED  deadlockedLec 10.72/18/10 CS162 ©UCB Fall 2010Deadlock Detection Algorithm Example T1T2T3R2R1T4[Available] = [0,0][RequestT2] = [0,0][RequestT2] <= [Available]T1T2T3R2R1T4[Available] = [1,0][RequestT1] = [1,0][RequestT1] <= [Available]T1T2T3R2R1T4[Available] = [1,1][RequestT3] = [0,1][RequestT3] <= [Available]…Lec 10.82/18/10 CS162 ©UCB Fall 2010What to do when detect deadlock?•Terminate thread, force it to give up resources–In Bridge example, Godzilla picks up a car, hurls it into the river. Deadlock solved!–Shoot a dining philosopher–But, not always possible – killing a thread holding a mutex leaves world inconsistent•Preempt resources without killing off thread –Take away resources from thread temporarily–Doesn’t always fit with semantics of computation•Roll back actions of deadlocked threads –Hit the rewind button on TiVo, pretend last few minutes never happened–For bridge example, make one car roll backwards (may require others behind him)–Common technique in databases (transactions)–Of course, if you restart in exactly the same way, may reenter deadlock once againLec 10.92/18/10 CS162 ©UCB Fall 2010Techniques 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:»Bay 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 retryLec 10.102/18/10 CS162 ©UCB Fall 2010Techniques 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 clockwiseLec 10.112/18/10 CS162 ©UCB Fall 2010Review: Train Example (Wormhole-Routed Network)•Circular dependency (Deadlock!)–Each train wants to turn right–Blocked by other trains–Similar problem to multiprocessor


View Full Document

Berkeley COMPSCI 162 - Lecture 10 Deadlock Thread Scheduling

Documents in this Course
Lecture 1

Lecture 1

12 pages

Nachos

Nachos

41 pages

Security

Security

39 pages

Load more
Download Lecture 10 Deadlock Thread Scheduling
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 10 Deadlock Thread Scheduling 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 10 Deadlock Thread Scheduling 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?