1 / 34

CH 3 Deadlock

CH 3 Deadlock. When 2 (or more) processes remain blocked forever !. Process a Down x Gets x Down y Blocks. Process b Down y Gets y Down x Blocks. How can this happen?. Both are blocked forever !. Resources. Things for which we request exclusive access.

dionysus
Download Presentation

CH 3 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. CH 3 Deadlock When 2 (or more) processes remain blocked forever!

  2. Process a Down x Gets x Down y Blocks Process b Down y Gets y Down x Blocks How can this happen? Both are blocked forever!

  3. Resources • Things for which we request exclusive access. • Ex. db, files, shared memory, printer, cd/dvd writer, tape drive, etc. • Types • Preemptable – can be taken away w/out ill effects • Non preemptable – cannot be take away w/out causing a failure

  4. Resource examples • Memory – preemptable • CPU – preemptable • CD writing – non preemptable • Printing – non preemptable • We will only consider non preemptable (the harder problem).

  5. Deadlock • 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.

  6. Conditions for deadlock • Mutual exclusion • Hold and wait • No preemption • Circular wait (Need all of these (all necessary).)

  7. Resource allocation graph resource process

  8. (Directed)Graphs • A graph G = (V,E) where V = vertex set and E = edge set • Ordered pairs of vertices • Ex. Let G = (V,E) where V = { C, D, T, U } and E = { <D,U>, <U,C>, <C,T>, <T,D> }

  9. Dealing w/ deadlock • Ignore it (ostrich algorithm). • Detect and recover. • Avoid by careful resource allocation. • Disallow one or more of the conditions necessary for deadlock.

  10. 2. Detect and recover • Detection with one resource of each type • Detection with multiple resources of each type

  11. Detection with one resource of each type • Detect cycle in digraph • For each vertex v in graph, • search the subtree rooted at v • see if we visit any vertex twice (by keeping a record of already visited vertices).

  12. Detection with multiple resources of each type • Skip.

  13. Recovery • Preemption • Rollback (using checkpoints) • Kill process

  14. Recovery: preemption • Temporarily take back needed resource • Ex. Printer • Pause at end of page k • Start printing other job • Resume printing original job starting at page k+1

  15. Recovery: rollback • Checkpoint – save entire process state (typically right before the resource was allocated) • When deadlock is detected, we kill the checkpointed process, freeing the resource, and then later restart the killed process starting at the checkpoint. • Requires apps that can be restarted in this manner.

  16. Rdb’s & commit/rollback From p. 62, http://www.postgresql.org/files/documentation/pdf/8.0/postgresql-8.0-US.pdf

  17. Recovery: kill process • Requires apps that can be restarted from the beginning.

  18. Deadlock avoidance • Safe state = not deadlocked and there exists some scheduling order in which every process can run to completion even if all of them suddenly request their max number of resources immediately • Unsafe != deadlocked

  19. Safe states

  20. Unsafe states

  21. Banker’s algorithm (for single resource type) • Grant only those requests that lead to safe states. • Requires future information.

  22. Banker’s algorithm • (b) is safe because from (b) we can give C 2 more (free=0) then C completes (free=4) then give either B or D . . .

  23. Banker’s algorithm • (c) is unsafe because no max can be satified

  24. Banker’s algorithm (multiple resources) N: E=existing (free) P=possessed (allocated/held) A=available ∑

  25. Banker’s algorithm (multiple resources) To check for a safe state: • Look for a row, R, in N <= A. • Assume the process of the chosen row requests all resources, runs to completion, and terminates (giving back all of its resources to A). • Repeat steps 1 and 2 until either all processes either terminate (indicating that the initial state was safe) or deadlock occurs.

  26. Banker’s algorithm (multiple resources) To check for a safe state: • Look for a row, R, in N <= A.

  27. Deadlock prevention • Attack: • Mutual exclusion • Hold and wait • No preemption • Circular wait

  28. Deadlock prevention: attack mutex • Ex. Use spooling instead of mutex on printer • No all problems lend themselves to spooling • Still have contention for disk space with spooling

  29. Deadlock prevention: attack hold & wait • Request (wait for) all resources prior to process execution • Problems: • We may not know a priori. • We tie up resources for entire time. • Before requesting a resource, we must first temporarily release all allocated resources and then try to acquire all of them again.

  30. Deadlock prevention: attack no preemption • Tricky at best. • Impossible at worst.

  31. Deadlock prevention: attack circular wait • Only allow one resource at a time. • Request all resources in (some globally assigned) numerical order. • No numerical ordering may exist.

More Related