1 / 24

Deadlocks

Deadlocks. CPE 261403 - Operating Systems http://www.e-cpe.org/moodle. Conditions of a Deadlock (7.2.1). Mutual exclusion Hold and wait No preemption Circular wait. Which of these are in a deadlock?. Methods for Handling Deadlocks. Never allow a deadlock state

Télécharger la présentation

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. Deadlocks CPE 261403 - Operating Systems http://www.e-cpe.org/moodle

  2. Conditions of a Deadlock (7.2.1) • Mutual exclusion • Hold and wait • No preemption • Circular wait

  3. Which of these are in a deadlock?

  4. Methods for Handling Deadlocks • Never allow a deadlock state • Allow deadlock and then recover • Ignore the problem

  5. Deadlock Prevention(7.4)Prevent deadlock conditions from occurring • Mutual exclusion • Hold and wait • No preemption • Circular wait

  6. Deadlock Avoidance(7.5) Figure 7.5

  7. Example Total number of resources = 12

  8. Resource Allocation Graph Safe Unsafe

  9. Banker’s Algorithm Let n = number of processes, and m = number of resources types. • Available: Vector of length m. If available [j] = k, there are k instances of resource type Rjavailable. • Max: n x m matrix. If Max [i,j] = k, then process Pimay request at most k instances of resource type Rj. • Allocation: n x m matrix. If Allocation[i,j] = k then Pi is currently allocated k instances of Rj. • Need: n x m matrix. If Need[i,j] = k, then Pi may need k more instances of Rjto complete its task. Need [i,j] = Max[i,j] – Allocation [i,j].

  10. Example 3 resource types: A (10 instances), B (5instances), and C (7 instances). Time T0 MAX Allocation

  11. Safety Algorithm Available Need Finish

  12. Safety Algorithm Available Need Finish

  13. Example (Cont.) • The content of the matrix Need is defined to be Max – Allocation. Need A B C P0 7 4 3 P1 1 2 2 P2 6 0 0 P3 0 1 1 P4 4 3 1 • The system is in a safe state since the sequence < P1, P3, P4, P2, P0> satisfies safety criteria.

  14. Process P1 makes a request for: 1 instance of A 2 instance of C Request Vector = (1,0,2)

  15. Safety Algorithm after (1,0,2) request Work Need Finish

  16. Example: P1 Request (1,0,2) • Check that Request  Available (that is, (1,0,2)  (3,3,2)  true. AllocationNeedAvailable A B C A B C A B C P0 0 1 0 7 4 3 2 3 0 P1 3 0 2 0 2 0 P2 3 0 1 6 0 0 P3 2 1 1 0 1 1 P4 0 0 2 4 3 1 • Executing safety algorithm shows that sequence < P1, P3, P4, P0, P2> satisfies safety requirement. • Can request for (3,3,0) by P4 be granted? • Can request for (0,2,0) by P0 be granted?

  17. Deadlock Detection (7.6)

  18. Wait-for Graphs (single instance system only) Resource-Allocation Graph Corresponding wait-for graph

  19. Wait-for Graph does not work with multiple instance resources

  20. Banker’s Algorithm as a deadlock detection tool for multiple instance systems

  21. Deadlock Recovery (7.7)

  22. Process Termination • Abort all deadlock processes • Abort one at a time until deadlock cycle is eliminated

  23. Resource Preemption • Selecting a victim – minimize cost. • Rollback – return to some safe state, restart process for that state. • Starvation – same process may always be picked as victim, include number of rollback in cost factor.

More Related