Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
2Activity
0 of .
Results for:
No results containing your search query
P. 1
Lec10 Scheduling

Lec10 Scheduling

Ratings: (0)|Views: 12|Likes:
Published by minhhai2209

More info:

Published by: minhhai2209 on Aug 27, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

09/13/2010

pdf

text

original

 
CS162Operating Systems andSystems ProgrammingLecture 10Deadlock (cont’d)Thread Scheduling
October 1, 2008Prof. John Kubiatowiczhttp://inst.eecs.berkeley.edu/~cs162
Lec10.210/01/08Kubiatowicz CS162 ©UCB Fall 2008
Review: 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 acquireadditional resources held by other threads
No preemption
»
Resources are released only voluntarily by the threads
Circular wait
»
There exists a set {
1
, …,
n
 } of threads with a cyclicwaiting pattern
Lec10.310/01/08Kubiatowicz CS162 ©UCB Fall 2008
Review: Resource Allocation Graph Examples
1
2
3
R
1
R
2
R
3
R
4
Simple ResourceAllocation Graph
1
2
3
R
1
R
2
R
3
R
4
Allocation GraphWith Deadlock
1
2
3
R
2
R
1
4
Allocation GraphWith Cycle, butNo Deadlock
Recall:
request edge –directed edge
1
 j 
assignment edge –directed edge
 j 
Lec10.410/01/08Kubiatowicz CS162 ©UCB Fall 2008
Review: Methods for Handling Deadlocks
Allow system to enter deadlock and then recover
Requires deadlock detection algorithm
Some technique for selectively preempting resourcesand/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 deadlocksnever occur in the system
used by most operating systems, including UNIX
 
Lec10.910/01/08Kubiatowicz CS162 ©UCB Fall 2008
Techniques for Preventing Deadlock (con’t)
Make all threads request everything they’ll need atthe 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 anyintersection between here and where you want to go; onlyone car on the Bay Bridge at a time
Force all threads to request resources in a particularorder 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 requiringeveryone to go clockwise
Lec10.1010/01/08Kubiatowicz CS162 ©UCB Fall 2008
Review: Train Example (Wormhole-Routed Network)
Circular dependency (Deadlock!)
Each train wants to turn right
Blocked by other trains
Similar problem to multiprocessor networks
Fix? Imagine grid extends in all four directions
Force ordering of channels(tracks)
»
Protocol: Always go east-west first, then north-south
Called “dimension ordering”(X then Y)
 
i  s  l  l  w  d  B   y   R  u  l  
Lec10.1110/01/08Kubiatowicz CS162 ©UCB Fall 2008
Toward right idea:
State maximum resource needs in advance
Allow particular thread to proceed if:
(available resources -#requested)
maxremaining that might be needed by any thread
Banker’s algorithm (less conservative):
Allocate resources dynamically
»
Evaluate each request and grant if someordering of threads is still deadlock free afterward
»
Technique: pretend each request is granted, then rundeadlock detection algorithm, substituting([Max
node
]-[Alloc
node
]
[Avail]) for ([Request
node
]
[Avail])Grant request if result is deadlock free (conservative!)
»
Keeps system in a “SAFE”state, i.e. there exists asequence {T 
1
, T 
2
, …
n
 } with T 
1
requesting all remainingresources, finishing, then T 
2
requesting all remainingresources, etc..
Algorithm allows the sum of maximum resource needs of allcurrent threads to be greater than total resources
Banker’s Algorithm for Preventing Deadlock
Lec10.1210/01/08Kubiatowicz CS162 ©UCB Fall 2008
Banker’s Algorithm Example
Banker’s algorithm with dining lawyers
“Safe(won’t cause deadlock) if when try to grabchopstick either:
»
Not last chopstick
»
Is last chopstick but someone will havetwo afterwards
What if k-handed lawyers? Don’t allow if:
»
It’s the last one, no one would have k
»
It’s 2
nd
to last, and no one would have k-1
»
It’s 3
rd
to last, and no one would have k-2
»

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->