170 likes | 292 Views
ITFN 2601 Introduction to Operating Systems. Lecture 6 Deadlock Deadlock Recovery. Agenda. What is a Resource? Deadlock Defined Conditions for Deadlock Resource Allocation Graphs Dealing with Deadlock. Resources. An object granted Hardware (disk, cpu)
E N D
ITFN 2601Introduction to Operating Systems Lecture 6 Deadlock Deadlock Recovery
Agenda • What is a Resource? • Deadlock Defined • Conditions for Deadlock • Resource Allocation Graphs • Dealing with Deadlock
Resources • An object granted • Hardware (disk, cpu) • Piece of Information (memory, record in DB) • Preemptable & non-preemptable
Utilizing a Resource • Request resource • Use Resource • Release resource • Use a semaphore/mutex to get/release lock on resource
Deadlock Defined • From our childhood… • I’ve got the ball and want the bat • You’ve got the bat and want the ball • “A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause.”
Conditions for Deadlock • Mutual exclusion of resource • Hold and Wait (processes with a resource can request other resources) • Non-preemptable resources • Circular wait (chain of processes in wait) • See RAGs (next slide)
Resource Allocation Graphs • Figure 6-3 D A S T U R B C Process Aholdingresource R Process Brequestingresource S Circularity = Deadlock
Dealing with Deadlock • Ostrich Algorithm (today) • Detection & Recovery (today) • Dynamic Avoidance (next lecture) • Prevention (next lecture)
Ostrich Algorithm • Stick your head in the sand and pretend there is no problem at all • What is the typical use of the system? • What is the probability of deadlock? • Do the costs associated with dealing w/ deadlock outweigh the benefits?
Detection & Recovery • One resource of each type • Multiple resource of each type • Preemption • Rollback • Killing Processes
Detection (1 resource) • Detect cycle in RAG • Use a directed graph • Utilize an optimized cycle detection algorithm – speed essential!
Detection (multiple resource) • “Forget about it”
OK, Now What? • Once we’ve detected deadlock… • Handle it • Preemption • Rollback • Killing Processes
Preemption • Not always possible • Highly dependant upon the resource • Typically associated w/ hardware resources • Some examples • Suspending a large print job • CD-burner
Rollback • Save the state of each process periodically (checkpoint) • Restore the process w/ the needed resource to an earlier checkpoint (before it acquired the resource) • Then the resource is now available • Drawback – “rolled back” process loses work
Killing Processes • Again, not always an option • DB transactions cannot always be killed midway through! • Kill process to free up resource
Summary • Resources can be preeptable & nonpreemptable • Deadlock can cause processes to halt (stop making progress) • We can detect deadlock • RAGs are quite useful • Ostrich algorithm quite popular