1 / 16

Deadlocks

Deadlocks. fig_13_00. Example: Tasks T0 and T1 must share resources R1 and R2 They will communicate with semaphores S0 and S1 Instruction flow: T0 sets S0 = 1 and waits for R1 T0 sets S1 = 1 and waits for R2 T1 sets S1 = S1 + 1 = 2 and waits for R2 T1 sets S0 = S0 + 1 = 2 and waits for R1

Download Presentation

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

  2. fig_13_00 Example: Tasks T0 and T1 must share resources R1 and R2 They will communicate with semaphores S0 and S1 Instruction flow: T0 sets S0 = 1 and waits for R1 T0 sets S1 = 1 and waits for R2 T1 sets S1 = S1 + 1 = 2 and waits for R2 T1 sets S0 = S0 + 1 = 2 and waits for R1 No way for either task to make progress: deadlock

  3. fig_13_00 Example system: similar (identical copies) and dissimilar resources to be shared fig_13_00

  4. fig_13_00 • Necessary conditions for deadlock: • --All must hold simultaneously • --These conditions are not sufficient and not independent • Mutual exclusion—if process gets control of a resource no other process can use it • Hold and wait—there are processes holding resources and requesting resources held by other processer • No preemption—resources cannot be preempted by another process • Circular wait—there is a set of processes P0, P1, …Pn where • Pi is waiting for a resource held by Pi+1, i = 0,…,n-1 and • Pn is waiting for a resource held by P0

  5. fig_13_01 Deadlock analysis tool: resource allocation graph Example: suppose we have the following system of tasks and resource, where dots indicate copies of a type of resource: Waiting for resource:Holding resource: fig_13_01

  6. fig_13_02 Example state: --if no cycles, there is no deadlock; --if there is a cycle, there is a potential for deadlock fig_13_02

  7. fig_13_03 Example: cycle (T1,R1,T2,R5) and deadlock fig_13_03

  8. fig_13_04 Example: cycle (T1,R1,T2,R5) but no deadlock fig_13_04

  9. fig_13_05 Deadlock prevention: Can prevent one of necessary conditions Mutual exclusion—cannot guarantee this won’t occur, some resources are not sharable Hold and wait can require task get all resources before executing—may be inefficient Can require running task give up resources before getting a new one—may lead to starvation of low priority tasks No preemption Can allow preemption; similar problems to Hold and wait No circular wait Can put a linear order on the resources and use this to constrain task requests

  10. fig_13_05 Deadlock avoidance: Algorithms need more information about how tasks use resources Example: two tasks share two resources but task scheduling guarantees that they will not both request the same resource during a given interval fig_13_05

  11. fig_13_06 Example graph-based algorithm: using claim and request edges Claim edge: task may request resource, calculated at beginning Request edge: actual request, convert a claim edge Example: T1 has a claim on R1 but cannot request it at this time because a deadlock will occur fig_13_06

  12. fig_13_07 Deadlock Avoidance: Banker’s algorithm Each task must state total resources it needs when it enters; “banker” uses this information to construct a schedule ensuring that an “unsafe state” will never be entered fig_13_07

  13. fig_13_08 Example: A/D converter—10 channels fig_13_08

  14. fig_13_09 A safe state: 2 channels are not allocated Possible schedule: T0 gets 2 free channels, completes Then T2 and finally T1 can complete fig_13_09

  15. fig_13_10 Poor allocation: Let T1 go first; it will be blocked eventually and deadlock will occur fig_13_10

  16. fig_13_11 Deadlock recovery: --Task termination—simple but may be too severe --Resource preemption Must take into consideration --which task to preempt --rollback considerations --starvation fig_13_11

More Related