1 / 21

Lecture 13 Chapter 7: Deadlocks

Lecture 13 Chapter 7: Deadlocks. Chapter 7: Deadlocks. The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection Recovery from Deadlock . Chapter Objectives.

Antony
Télécharger la présentation

Lecture 13 Chapter 7: Deadlocks

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. Lecture 13Chapter 7: Deadlocks

  2. Chapter 7: Deadlocks • The Deadlock Problem • System Model • Deadlock Characterization • Methods for Handling Deadlocks • Deadlock Prevention • Deadlock Avoidance • Deadlock Detection • Recovery from Deadlock

  3. Chapter Objectives • To develop a description of deadlocks, • which prevent sets of concurrent processes from completing their tasks • To present a number of different methods for preventing or avoiding deadlocks in a computer system

  4. The Deadlock Problem • A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set • Example • System has 2 disk drives • P1 and P2 each hold one disk drive and each needs another one • Example • semaphores A and B, initialized to 1 P0P1 wait (A); wait(B) wait (B); wait(A)

  5. Bridge Crossing Example • Traffic only in one direction • Each section of a bridge can be viewed as a resource • If a deadlock occurs, it can be resolved if one car backs up • preempt resources and rollback • Several cars may have to be backed up if a deadlock occurs • Starvation is possible • Note : Most OSes do not prevent or deal with deadlocks

  6. Deadlock Principles • A deadlock is a permanent blocking of a set of threads • a deadlock can happen while threads/processes are competing for system resources or communicating with each other Tanenbaum, A. S. (2001) Modern Operating Systems (2nd Edition). Illustration of a deadlock

  7. A required B required B required A required Deadlock Principles • Illustration of a deadlock— scheduling path 1  • Q executes everything before P can ever get A • when P is ready, resources A and B are free and P can proceed Happy scheduling 1

  8. A required B required B required A required Deadlock Principles • Illustration of a deadlock— scheduling path 2  • Q gets B and A, then P is scheduled; P wants A but is blocked by A’s mutex; so Q resumes and releases B and A; P can now go Happy scheduling 2

  9. A required B required deadlock B required A required Deadlock Principles • Illustration of a deadlock— scheduling path 3  • Q gets only B, then P is scheduled and gets A; now both P and Q are blocked, each waiting for the other to release a resource Bad scheduling deadlock

  10. Deadlock Principles Stallings, W. (2004) Operating Systems: Internals and Design Principles (5th Edition). Joint progress diagram

  11. program design • the order of the statements in the code creates the “landscape” of the joint progress diagram • this landscape may contain gray “swamp” areas leading to deadlock swamps • scheduling condition • the interleaved dynamics of multiple executions traces a “path” in this landscape • this path may sink in the swamps swamps Deadlock Principles • Deadlocks depend on the program and the scheduling

  12. B required A required Deadlock Principles • Changing the program changes the landscape • here, P releases A before getting B • deadlocks between P and Q are not possible anymore A required B required Competing processes

  13. Deadlock Principles Joint progress diagram • no swamp area: there exists no path leading to deadlock Stallings, W. (2004) Operating Systems: Internals and Design Principles (5th Edition).

  14. System Model • Resource types R1, R2, . . ., Rm CPU cycles, memory space, I/O devices • Each resource type Ri has Wi instances. • Each process utilizes a resource as follows: • request • use • release

  15. Deadlock Characterization • Mutual exclusion: only one process at a time can use a resource • Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes • No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task • Circular wait: there exists a set {P0, P1, …, P0} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and P0 is waiting for a resource that is held by P0. Deadlock can arise if four conditions hold simultaneously.

  16. Resource-Allocation Graph • V is partitioned into two types: • P = {P1, P2, …, Pn}, the set consisting of all the processes in the system • R = {R1, R2, …, Rm}, the set consisting of all resource types in the system • request edge – directed edge P1  Rj • assignment edge – directed edge Rj Pi A set of vertices V and a set of edges E.

  17. Resource-Allocation Graph (Cont.) • Process • Resource Type with 4 instances • Pirequests instance of Rj • Pi is holding an instance of Rj Pi Rj Pi Rj

  18. Example of a Resource Allocation Graph

  19. Resource Allocation Graph With A Deadlock

  20. Graph With A Cycle But No Deadlock

  21. Basic Facts • If graph contains no cycles  no deadlock • If graph contains a cycle  • if only one instance per resource type, then deadlock • if several instances per resource type, possibility of deadlock

More Related