1 / 29

Deadlock

Deadlock. Chapter 3 Thursday, February 22, 2007. Today’s Schedule. Assignment #4 from Chapter 3 posted Deadlock - Chapter 3 Skip multiple resources (3.4.2 & 3.5.4). Today’s Objectives . You will be able to describe: Several causes of system deadlock

ellema
Download Presentation

Deadlock

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Deadlock Chapter 3 Thursday, February 22, 2007

  2. Today’s Schedule • Assignment #4 from Chapter 3 posted • Deadlock - Chapter 3 • Skip multiple resources (3.4.2 & 3.5.4)

  3. Today’s Objectives You will be able to describe: • Several causes of system deadlock • The difference between preventing and avoiding deadlocks • How to detect and recover from deadlocks • How to prevent deadlock

  4. Overview • A lack of process synchronization results in deadlock or starvation • Deadlock: • A system-wide tangle ofresource requests that begins when two or more jobs are put on hold • Each job waiting for a vital resource to become available • The jobs come to a standstill • Resolved via external intervention • Starvation: Infinite postponement of a job

  5. Starvation Which of the following scheduling algorithms could result in starvation? If so, how? • First-come, First-served • Shortest job first • Round robin • Priority

  6. Deadlock • Affects more than one job, hence more serious than starvation • System (not just a few programs) is affected as resources are being tied up • e.g., Traffic jam

  7. Deadlock in Spooling • Virtual device:Sharable device—e.g., a printer transformed by installing a high-speeddevice, a disk, between it and the CPU • Spooling:Disk accepts output from several users and acts as atemporary storage area for all output until printer is readyto accept it • Deadlock in spooling:If printer needs all of a job's output before it will beginprinting, but spooling system fills available disk space withonly partially completed output

  8. Deadlock Defined • From our more playful days … • 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.”

  9. Modeling DeadlocksResource Allocation Graphs Process P1 requests Resource R1 Process P1 holdsResource R1

  10. How deadlock occurs A B C Cycle formed!!

  11. How deadlock can be avoided (o) (p) (q)

  12. Conditions Required for Deadlock • Mutual exclusion conditioneach resource assigned to 1 process or is available • Hold and wait conditionprocess holding resources can request additional • No preemption conditionpreviously granted resources cannot forcibly taken away • Circular wait conditionmust be a circular chain of 2 or more processeseach is waiting for resource held by next member of the chain

  13. Dealing with Deadlock • Ostrich Algorithm Ignore deadlock possibility! • Detection & Recovery • Dynamic Avoidance • careful resource allocation • Prevention • negating one of the four necessary conditions

  14. Ostrich Algorithm • Stick your head in the sand and pretend there is no problem at all • Reasonable if • deadlocks occur very rarely • cost of prevention is high • UNIX and Windows takes this approach • Trade off between • convenience • correctness • 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?

  15. Detecting Deadlock – Find Cycle • Note the resource ownership and requests • A cycle can be found within the graph, denoting deadlock

  16. How to Recover from Deadlock? • Recovery through preemption • take a resource from some other process • depends on nature of the resource • Recovery through rollback • checkpoint a process periodically • use this saved state • restart the process if it is found deadlocked • Recovery through killing processes • crudest but simplest way to break a deadlock • kill one of the processes in the deadlock cycle

  17. Avoid Deadlock Resource Trajectories Show B Impossible Printer I9 I8 I7 I6 Plotter t u Unsafe r s A p q I1 I2 I3 I4 I5 Printer Plotter

  18. Safe/Unsafe States • Safe State • Not in deadlock • There is some scheduling order with which all processes can finish • Unsafe State • Not necessarily deadlock • Doesn’t guarantee deadlock • But can’t guarantee deadlock will be avoided

  19. Avoid Deadlock Unsafe State deadlock Safe State

  20. Banker’s Algorithm – Avoid Deadlock • Regulate resource allocation • No loan exceeding bank’s total capital • Customers have a pre-set maximum credit • May not borrow over the limit • Total of all loans may not exceed bank’s capital

  21. Avoidance (continued) Safestate: Bank still has enough money left after loans to satisfy the maximum requestsof C1, C2, or C3 The bank started with$10,000 and has remainingcapital of $4,000 afterthese loans

  22. Avoidance (continued) Unsafe state: Bank does not have enough money left after loans to satisfy the maximum requestsof C1, C2, or C3 Table 5.5: The bank hasremaining capital ofonly $1,000 after these loansand therefore is in an“unsafe state”

  23. Avoidance (continued) Same banking principles can be applied to an operating system Table 5.6: Asafe state: six devices areallocated and four unitsare stillavailable

  24. Avoidance (continued) Anunsafe state: only oneunit is available butevery job requires atleast two to complete itsexecution

  25. Deadlock Avoidance • To avoid deadlock, OS must make sure: • Never satisfy a request that moves it from a safestate to an unsafe one • Must identify the job with the smallest number of remaining resources • Number of available resources is always equal to, or greater than, the numberneeded for the selected job to run to completion

  26. Attack Deadlock Conditions • Attack Mutual Exclusion • Attack Hold and Wait • Require all process to request all resources before starting execution • Resource must temporarily release all the resources it currently holds • Attack No preemption • Just take away resource, does not work • Attack Circular Wait condition • Process is entitled to single resource at any moment • Use of global numbering • All requests made in numerical order

  27. Summary • Resources can be preemptable & nonpreemptable • Deadlock can cause processes to halt (stop making progress) • We can detect deadlock • RAGs are quite useful to detect deadlock • Ostrich algorithm quite popular

  28. Summary (cont) • Trajectories can help in process scheduling to avoid deadlock • Avoid unsafe states • Prevent Deadlock by attack one of four necessary conditions • Ordering resources avoids circular wait • Keep processes from starving – all processes must make some progress

  29. Tuesday, Feb 27, Memory • Complete Assignment #4 • Begin reading Chapter 4 – Memory Management

More Related