Concurrency:  Principles of Deadlock Operating Systems  Fall 2002
Processes and resources Processes need  resources  to run CPU, memory, disk, etc… A process waiting for a resource cannot complete its execution until the resource becomes available There is only a finite amount of resources E.g., 1 CPU, 1 GB memory, 2 disks
Concurrency and deadlocks In a multiprogramming system the total resource demand by all concurrently active processes exceeds by far the total amount of available resources Processes compete for resources A process can grab the last instance of a resource A and wait for the resource B Another process may hold B and wait for A No one can proceed: Deadlock
Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other Involves conflicting needs for resources by two or more processes There is no satisfactory solution in the general case
Deadlock in the everyday life 1 2 3 4
Deadlock in the everyday life
Deadlock when contending for the critical section
Example of Deadlock Progress of Q Release A Release B Get A Get B Get A Get B Release A Release B Progress of P A Required B Required A Required B Required deadlock inevitable 1 2 3 4 5 6 P and Q want A P and Q want B
Example of No Deadlock Progress of Q Release A Release B Get A Get B Get A Release A Get B Release B Progress of P A Required B Required A Required B Required 1 2 3 4 5 6 P and Q want A P and Q want B
Resource categories Reusable : Used by one process at a time and not depleted by that use can be reused by other processes,may exist several instances Processors, memory, disks, tapes, etc. Consumable : Created (produced) and destroyed (consumed) by a process Interrupts, signals, messages, and information in I/O buffers
Reusable resources and Deadlock Deadlock might occur if each process holds one resource and requests the other E.g., Space is available for allocation of 200K P1 . . . . . . Request 80K bytes; Request 60K bytes; P2 . . . . . . Request 70K bytes; Request 80K bytes;
Consumable resources and Deadlock Example: Deadlock occurs if receive is blocking P1 . . . . . . Receive(P2); Send(P2); P2 . . . . . . Receive(P1); Send(P1);
Conditions for Deadlock Policy conditions Mutual exclusion Hold-and-wait No preemption Circular wait Process P1 Process P2 Requests Held by Requests Held By Resource B Resource A
Conditions for Deadlock Mutual exclusion Hold-and-wait No preemption Circular wait DEADLOCK
Circular Wait P1 P2 P3 R1 R2 R3
No circular wait P1 P2 P3 R1 R2 R3
Coping with Deadlocks Deadlock prevention Deadlock possibility is excluded a priori by the system design Deadlock avoidance Deadlocks are possible in principle but avoided Deadlock detection Deadlocks can occur: detect and solve the problem
Deadlock prevention Design system so that it violates one of the four necessary conditions Prevent hold and wait: request all the resources at the outset wait until all the resources are available Prevent circular wait by defining linear ordering of the resource types A process holding some resources can request only resource types with higher numbers
Preventing circular wait P1 P2 P3 R1 R2 R3
Deadlock prevention: Cons Degraded performance Delayed execution Low parallelism  Hold and wait prevention is wasteful Hold resources more than they are needed When might this be reasonable?
Deadlock avoidance Allocate resources in a way that assures that the deadlock point is never reached The allocation decision is made  dynamically   based on total amount of resources available currently available processes’ resource claim processes’ current resources allocation
Banker’s algorithm ( Dijkstra 65’ ) Do not grant an incremental resource request to a process is this allocation might lead to deadlock The system  state : is the current allocation of resources to processes Safe state: is a state in which there is at least one sequence in which all processes can be run to completion Unsafe state = NOT safe state
Determination of the safe state We have 3 resources types with amount: R(1) = 9, R(2) = 3, R(3) = 6 Is the state S0 below safe? Claim  Allocated  Total 3  2  2 6  1  3 3  1  4 4  2  2 1  0  0 6  1  2 2  1  1 0  0  2 P1 P2 P3 P4 R1  R2  R3 R1  R2  R3 R1  R2  R3 9  3  6 Available 0  1  1
Determination of the safe state Claim  Allocated  Total 3  2  2 0  0  0 3  1  4 4  2  2 1  0  0 0  0  0 2  1  1 0  0  2 P1 P2 P3 P4 R1  R2  R3 R1  R2  R3 R1  R2  R3 9  3  6 Available 6  2  3 Claim  Allocated  Total 0  0  0 0  0  0 3  1  4 4  2  2 0  0  0 0  0  0 2  1  1 0  0  2 P1 P2 P3 P4 R1  R2  R3 R1  R2  R3 R1  R2  R3 9  3  6 Available 7  2  3
Determination of the safe state Claim  Allocated  Total 0  0  0 0  0  0 0  0  0 4  2  2 0  0  0 0  0  0 0  0  0 0  0  2 P1 P2 P3 P4 R1  R2  R3 R1  R2  R3 R1  R2  R3 9  3  6 Available 9  3  4 Claim  Allocated  Total 0  0  0 0  0  0 0  0  0 0  0  0 0  0  0 0  0  0 0  0  0 0  0  0 P1 P2 P3 P4 R1  R2  R3 R1  R2  R3 R1  R2  R3 9  3  6 Available 9  3  6 S0 is safe: P2->P1->P3->P4
Banker’s algorithm When a process request resources: Assume the request is granted Update the system state accordingly  Determine whether the resulting state is safe If yes: grant the resources Otherwise, block the process until it is safe to grant the resources
Banker’s algorithm Claim  Allocated  Total 3  2  2 6  1  3 3  1  4 4  2  2 1  0  0 5  1  1 2  1  1 0  0  2 P1 P2 P3 P4 R1  R2  R3 R1  R2  R3 R1  R2  R3 9  3  6 Available 1  1  2 P2 requests (1, 0, 1): Grant or not? P1 requests (1, 0, 1): Grant or not?
Deadlock detection Banker’s algorithm is Pessimistic: always assume that a process will not release the resources until it got’m all decreased parallelism  Involves complicated checks for each resource allocation request (O(n^2)) Optimistic approach: don’t do any checks When deadlock occurs - detect and recover Detection: look for circular waits
Practice Most operating systems employ an “ostrich” algorithm Break hold-and-wait Cannot acquire a resource - fail back to the user: e.g., too many processes, too many open files Quotas Programming discipline: acquire locks (semaphores) in a specific order
Dining philosophers problem
Dining philosophers problem An abstract problem demonstrating some fundamental limitations of the deadlock-free synchronization There is no symmetric solution Solutions execute different code for odd/even give’m another fork allow at most 4 philosophers at the table Randomized (Lehmann-Rabin)
Concurrency: summary Critical section is an abstract problem for studying concurrency and synchronization software solutions hardware primitives higher level primitives: semaphores, monitors Deadlocks are inherent to concurrency 4 conditions 3 ways to cope with
Next: Memory management

More Related Content

PDF
7 Deadlocks
PDF
Deadlock
PPTX
Deadlock detection & prevention
PPTX
Deadlock
PPT
Deadlock
PDF
Dead Lock In Operating Systems
7 Deadlocks
Deadlock
Deadlock detection & prevention
Deadlock
Deadlock
Dead Lock In Operating Systems

What's hot (20)

PDF
OS - Deadlock
PPT
Chapter06
PPTX
Operating system Dead lock
DOCX
Deadlocks 160928121516-160928183232
PPT
PPTX
Deadlocks in operating system
PDF
9 deadlock
PPTX
Deadlock ppt
PPT
Deadlock
PPT
Deadlocks
PPTX
Deadlock- Operating System
PDF
Lect05
PPTX
Deadlock in Operating System
PPTX
Deadlock Avoidance in Operating System
PPTX
Operating system - Deadlock
PPTX
Deadlock Presentation
PPT
Deadlocks
PPT
23 deadlock
PPT
Os6 2
OS - Deadlock
Chapter06
Operating system Dead lock
Deadlocks 160928121516-160928183232
Deadlocks in operating system
9 deadlock
Deadlock ppt
Deadlock
Deadlocks
Deadlock- Operating System
Lect05
Deadlock in Operating System
Deadlock Avoidance in Operating System
Operating system - Deadlock
Deadlock Presentation
Deadlocks
23 deadlock
Os6 2
Ad

Viewers also liked (20)

PPT
Operating System Deadlock Galvin
PDF
DOCX
Banker's note - Blackstone Synergy Pitch
PPT
Mca ii os u-3 dead lock & io systems
PPT
Java Threading
PDF
thread-clustering
PPT
Introduction to Operating system
PPSX
Deadlock_SVVSDM_DWD
PPT
Galvin-operating System(Ch8)
PDF
2009 Punjab Technical University B.C.A OPERATING SYSTEM Question paper
PPTX
PDF
C++ Actor Model - You’ve Got Mail ...
PPTX
Essentials of Multithreaded System Programming in C++
PPTX
Threads (operating System)
PPT
Operating System: Deadlock
PDF
Holography
PPT
Operating System 5
PDF
Unit II - 2 - Operating System - Threads
PPTX
Thread scheduling in Operating Systems
Operating System Deadlock Galvin
Banker's note - Blackstone Synergy Pitch
Mca ii os u-3 dead lock & io systems
Java Threading
thread-clustering
Introduction to Operating system
Deadlock_SVVSDM_DWD
Galvin-operating System(Ch8)
2009 Punjab Technical University B.C.A OPERATING SYSTEM Question paper
C++ Actor Model - You’ve Got Mail ...
Essentials of Multithreaded System Programming in C++
Threads (operating System)
Operating System: Deadlock
Holography
Operating System 5
Unit II - 2 - Operating System - Threads
Thread scheduling in Operating Systems
Ad

Similar to Lecture5 (20)

PDF
Chapter 5(five).pdf
PPTX
7308346-Deadlock.pptx
PPTX
deadlocks.pptx
PPT
Chapter 7 - Deadlocks
PPT
Principles of Operating system and types
PPT
Lecture 8 - Memory Management. It deals with memory management
PPTX
Deadlock
PPTX
Deadlock and Banking Algorithm
PPTX
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
PPT
PPT
PPTX
OSLec14&15(Deadlocksinopratingsystem).pptx
PPTX
Deadlock iOS topic ppt which goes deep into the deadlock.pptx
PPT
Deadlock principles in operating systems
PDF
Ch7 deadlocks
PDF
CH07.pdf
PPTX
Chapter 4
PPTX
Module 3 Deadlocks.pptx
PPTX
deadlock in OS.pptx
PPT
DeadlockMar21.ppt
Chapter 5(five).pdf
7308346-Deadlock.pptx
deadlocks.pptx
Chapter 7 - Deadlocks
Principles of Operating system and types
Lecture 8 - Memory Management. It deals with memory management
Deadlock
Deadlock and Banking Algorithm
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
OSLec14&15(Deadlocksinopratingsystem).pptx
Deadlock iOS topic ppt which goes deep into the deadlock.pptx
Deadlock principles in operating systems
Ch7 deadlocks
CH07.pdf
Chapter 4
Module 3 Deadlocks.pptx
deadlock in OS.pptx
DeadlockMar21.ppt

Lecture5

  • 1. Concurrency: Principles of Deadlock Operating Systems Fall 2002
  • 2. Processes and resources Processes need resources to run CPU, memory, disk, etc… A process waiting for a resource cannot complete its execution until the resource becomes available There is only a finite amount of resources E.g., 1 CPU, 1 GB memory, 2 disks
  • 3. Concurrency and deadlocks In a multiprogramming system the total resource demand by all concurrently active processes exceeds by far the total amount of available resources Processes compete for resources A process can grab the last instance of a resource A and wait for the resource B Another process may hold B and wait for A No one can proceed: Deadlock
  • 4. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other Involves conflicting needs for resources by two or more processes There is no satisfactory solution in the general case
  • 5. Deadlock in the everyday life 1 2 3 4
  • 6. Deadlock in the everyday life
  • 7. Deadlock when contending for the critical section
  • 8. Example of Deadlock Progress of Q Release A Release B Get A Get B Get A Get B Release A Release B Progress of P A Required B Required A Required B Required deadlock inevitable 1 2 3 4 5 6 P and Q want A P and Q want B
  • 9. Example of No Deadlock Progress of Q Release A Release B Get A Get B Get A Release A Get B Release B Progress of P A Required B Required A Required B Required 1 2 3 4 5 6 P and Q want A P and Q want B
  • 10. Resource categories Reusable : Used by one process at a time and not depleted by that use can be reused by other processes,may exist several instances Processors, memory, disks, tapes, etc. Consumable : Created (produced) and destroyed (consumed) by a process Interrupts, signals, messages, and information in I/O buffers
  • 11. Reusable resources and Deadlock Deadlock might occur if each process holds one resource and requests the other E.g., Space is available for allocation of 200K P1 . . . . . . Request 80K bytes; Request 60K bytes; P2 . . . . . . Request 70K bytes; Request 80K bytes;
  • 12. Consumable resources and Deadlock Example: Deadlock occurs if receive is blocking P1 . . . . . . Receive(P2); Send(P2); P2 . . . . . . Receive(P1); Send(P1);
  • 13. Conditions for Deadlock Policy conditions Mutual exclusion Hold-and-wait No preemption Circular wait Process P1 Process P2 Requests Held by Requests Held By Resource B Resource A
  • 14. Conditions for Deadlock Mutual exclusion Hold-and-wait No preemption Circular wait DEADLOCK
  • 15. Circular Wait P1 P2 P3 R1 R2 R3
  • 16. No circular wait P1 P2 P3 R1 R2 R3
  • 17. Coping with Deadlocks Deadlock prevention Deadlock possibility is excluded a priori by the system design Deadlock avoidance Deadlocks are possible in principle but avoided Deadlock detection Deadlocks can occur: detect and solve the problem
  • 18. Deadlock prevention Design system so that it violates one of the four necessary conditions Prevent hold and wait: request all the resources at the outset wait until all the resources are available Prevent circular wait by defining linear ordering of the resource types A process holding some resources can request only resource types with higher numbers
  • 19. Preventing circular wait P1 P2 P3 R1 R2 R3
  • 20. Deadlock prevention: Cons Degraded performance Delayed execution Low parallelism Hold and wait prevention is wasteful Hold resources more than they are needed When might this be reasonable?
  • 21. Deadlock avoidance Allocate resources in a way that assures that the deadlock point is never reached The allocation decision is made dynamically based on total amount of resources available currently available processes’ resource claim processes’ current resources allocation
  • 22. Banker’s algorithm ( Dijkstra 65’ ) Do not grant an incremental resource request to a process is this allocation might lead to deadlock The system state : is the current allocation of resources to processes Safe state: is a state in which there is at least one sequence in which all processes can be run to completion Unsafe state = NOT safe state
  • 23. Determination of the safe state We have 3 resources types with amount: R(1) = 9, R(2) = 3, R(3) = 6 Is the state S0 below safe? Claim Allocated Total 3 2 2 6 1 3 3 1 4 4 2 2 1 0 0 6 1 2 2 1 1 0 0 2 P1 P2 P3 P4 R1 R2 R3 R1 R2 R3 R1 R2 R3 9 3 6 Available 0 1 1
  • 24. Determination of the safe state Claim Allocated Total 3 2 2 0 0 0 3 1 4 4 2 2 1 0 0 0 0 0 2 1 1 0 0 2 P1 P2 P3 P4 R1 R2 R3 R1 R2 R3 R1 R2 R3 9 3 6 Available 6 2 3 Claim Allocated Total 0 0 0 0 0 0 3 1 4 4 2 2 0 0 0 0 0 0 2 1 1 0 0 2 P1 P2 P3 P4 R1 R2 R3 R1 R2 R3 R1 R2 R3 9 3 6 Available 7 2 3
  • 25. Determination of the safe state Claim Allocated Total 0 0 0 0 0 0 0 0 0 4 2 2 0 0 0 0 0 0 0 0 0 0 0 2 P1 P2 P3 P4 R1 R2 R3 R1 R2 R3 R1 R2 R3 9 3 6 Available 9 3 4 Claim Allocated Total 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 P1 P2 P3 P4 R1 R2 R3 R1 R2 R3 R1 R2 R3 9 3 6 Available 9 3 6 S0 is safe: P2->P1->P3->P4
  • 26. Banker’s algorithm When a process request resources: Assume the request is granted Update the system state accordingly Determine whether the resulting state is safe If yes: grant the resources Otherwise, block the process until it is safe to grant the resources
  • 27. Banker’s algorithm Claim Allocated Total 3 2 2 6 1 3 3 1 4 4 2 2 1 0 0 5 1 1 2 1 1 0 0 2 P1 P2 P3 P4 R1 R2 R3 R1 R2 R3 R1 R2 R3 9 3 6 Available 1 1 2 P2 requests (1, 0, 1): Grant or not? P1 requests (1, 0, 1): Grant or not?
  • 28. Deadlock detection Banker’s algorithm is Pessimistic: always assume that a process will not release the resources until it got’m all decreased parallelism Involves complicated checks for each resource allocation request (O(n^2)) Optimistic approach: don’t do any checks When deadlock occurs - detect and recover Detection: look for circular waits
  • 29. Practice Most operating systems employ an “ostrich” algorithm Break hold-and-wait Cannot acquire a resource - fail back to the user: e.g., too many processes, too many open files Quotas Programming discipline: acquire locks (semaphores) in a specific order
  • 31. Dining philosophers problem An abstract problem demonstrating some fundamental limitations of the deadlock-free synchronization There is no symmetric solution Solutions execute different code for odd/even give’m another fork allow at most 4 philosophers at the table Randomized (Lehmann-Rabin)
  • 32. Concurrency: summary Critical section is an abstract problem for studying concurrency and synchronization software solutions hardware primitives higher level primitives: semaphores, monitors Deadlocks are inherent to concurrency 4 conditions 3 ways to cope with