Scheduling in OS
-
Upload
jonathan-kane -
Category
Documents
-
view
217 -
download
0
description
Transcript of Scheduling in OS
-
CS162Operating Systems andSystems ProgrammingLecture 10
Deadlock (contd)Thread SchedulingOctober 4th, 2010Prof. John Kubiatowiczhttp://inst.eecs.berkeley.edu/~cs162
Lec 10.*10/04/10Kubiatowicz CS162 UCB Fall 2010
Review: DeadlockStarvation vs. DeadlockStarvation: thread waits indefinitelyDeadlock: circular waiting for resourcesDeadlockStarvation, but not other way aroundFour conditions for deadlocksMutual exclusionOnly one thread at a time can use a resourceHold and waitThread holding at least one resource is waiting to acquire additional resources held by other threadsNo preemptionResources are released only voluntarily by the threadsCircular waitThere exists a set {T1, , Tn} of threads with a cyclic waiting pattern
Lec 10.*10/04/10Kubiatowicz CS162 UCB Fall 2010
Review: Resource Allocation Graph ExamplesRecall:request edge directed edge T1 Rjassignment edge directed edge Rj Ti
Lec 10.*10/04/10Kubiatowicz CS162 UCB Fall 2010
Review: Methods for Handling DeadlocksAllow system to enter deadlock and then recoverRequires deadlock detection algorithmSome technique for selectively preempting resources and/or terminating tasksEnsure that system will never enter a deadlockNeed to monitor all lock acquisitionsSelectively deny those that might lead to deadlockIgnore the problem and pretend that deadlocks never occur in the systemused by most operating systems, including UNIX
Lec 10.*10/04/10Kubiatowicz CS162 UCB Fall 2010
Goals for TodayPreventing DeadlockScheduling Policy goalsPolicy OptionsImplementation Considerations
Note: 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.*10/04/10Kubiatowicz CS162 UCB Fall 2010
Deadlock Detection AlgorithmOnly one of each type of resource look for loopsMore General Deadlock Detection AlgorithmLet [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 XSee if tasks can eventually terminate on their own[Avail] = [FreeResources] Add all nodes to UNFINISHED do {done = true Foreach node in UNFINISHED { if ([Requestnode]