Presentation is loading. Please wait.

Presentation is loading. Please wait.

Deadlock Prevention & Avoidance Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki

Similar presentations


Presentation on theme: "Deadlock Prevention & Avoidance Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki"— Presentation transcript:

1 Deadlock Prevention & Avoidance Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki E-mail: hfujino@siue.edu CS 314 Operating Systems Deadlock_Detection/000

2 CS 314 Operating Systems Deadlock_Avoidance/001 Deadlock Prevention Try to prevent any one of the four necessary conditions for a deadlock  Mutual Exclusion  Hold & Wait  Circular wait  Non preemptive resources

3 CS 314 Operating Systems Deadlock_Avoidance/002 Attacking mutual exclusion Some resources inherently require mutual exclusion Mutual Exclusion = While a process is using a resource no other process can use the same resource Example Problem Printers Files for updates CD-Rs

4 CS 314 Operating Systems Deadlock_Avoidance/003 Attacking hold & wait  Require all processes to acquire all the needed resources at once (a) Resource request does not have to be at the beginning of a process (b) If any of the required resource is not available, drop everything (then try it again later) (c) Any process can not make a request for any new resource, while the process currently has any resource  A process does NOT have to request all the resources at once (a) Whenever an additional resource is needed, drop all what are possessed by this process and request everything at once (b) If any process steals your resource(s) when you temporarily have to wait until all resources become available

5 CS 314 Operating Systems Deadlock_Avoidance/004 Attacking hold & wait Possible “Hold & Wait” 1-(b) “Hold & Wait” 1-(a) 1-(c) Time # of resources acquired Time

6 CS 314 Operating Systems Deadlock_Avoidance/005 Attacking hold & wait Time # of resources acquired 2-(a) Another Process If any of resources is missing, drop everything Drop all what you possess first Then you try to get all you need # of resources acquired Time 2-(b)

7 CS 314 Operating Systems Deadlock_Avoidance/006 Attacking non-preemption The same problem we had for “mutual exclusion” “Attacking Non-Preemption” Problem = Allow preemption = You process can loose your resource at any time No one will be happy in loosing a CD-R drive in the middle of burning a CD

8 CS 314 Operating Systems Deadlock_Avoidance/007 Circular-Wait Assign unique ID for every non-sharable resource in a system Every process must start requesting resources in either ascending or descending order of resource IDs A B X1X1 Y2Y2 Z3Z3 Request (X, Y, Z) (Y, Z)

9 CS 314 Operating Systems Deadlock_Avoidance/008 Circular-Wait Assign unique ID for every non-sharable resource in a system Every process must start requesting resources in either ascending or descending order of resource IDs A B X1X1 Y2Y2 Z3Z3 Assigned Request (X, Y, Z) (Y, Z)

10 CS 314 Operating Systems Deadlock_Avoidance/009 Circular-Wait Assign unique ID for every non-sharable resource in a system Every process must start requesting resources in either ascending or descending order of resource IDs A B X1X1 Y2Y2 Z3Z3 Assigned Request (X, Y, Z) (Y, Z)

11 CS 314 Operating Systems Deadlock_Avoidance/010 Circular-Wait Assign unique ID for every non-sharable resource in a system Every process must start requesting resources in either ascending or descending order of resource IDs A B X1X1 Y2Y2 Z3Z3 Assigned (X, Y, Z) (Y, Z) Assigned Requested Deadlock

12 CS 314 Operating Systems Deadlock_Avoidance/011 Circular-Wait Assign unique ID for every non-sharable resource in a system Every process must start requesting resources in either ascending or descending order of resource IDs A B X1X1 Y2Y2 Z3Z3 Assigned (X, Y, Z) (Y, Z) Request Process B blocks Request

13 CS 314 Operating Systems Deadlock_Avoidance/012 Circular-Wait Assign unique ID for every non-sharable resource in a system Every process must start requesting resources in either ascending or descending order of resource IDs A B X1X1 Y2Y2 Z3Z3 Assigned (X, Y, Z) (Y, Z) Request Process B blocks Assigned Process A Completes

14 CS 314 Operating Systems Deadlock_Avoidance/013 Circular-Wait Assign unique ID for every non-sharable resource in a system Every process must start requesting resources in either ascending or descending order of resource IDs B X1X1 Y2Y2 Z3Z3 (Y, Z) Request

15 CS 314 Operating Systems Deadlock_Avoidance/014 Circular-Wait Assign unique ID for every non-sharable resource in a system Every process must start requesting resources in either ascending or descending order of resource IDs B X1X1 Y2Y2 Z3Z3 (Y, Z) Assigned Requested

16 CS 314 Operating Systems Deadlock_Avoidance/015 Circular-Wait Assign unique ID for every non-sharable resource in a system Every process must start requesting resources in either ascending or descending order of resource IDs B X1X1 Y2Y2 Z3Z3 (Y, Z) Assigned Process B completes

17 CS 314 Operating Systems Deadlock_Avoidance/016 Deadlock Avoidance When a process makes a request to a resource, the OS simulates if it will cause a deadlock in the future if no one releases their currently-held resource: If it will cause a deadlock If it will not cause a deadlock the request is denied (“unsafe state”) the requested resource is granted (“safe state”)

18 CS 314 Operating Systems Deadlock_Avoidance/016 The two states defined in Deadlock Avoidance A system is in “safe state” if there is at least one assignment schedule to complete all the processes without deadlock and without any process releasing their resources  Safe State  Unsafe State If a system is not in safe state, the system must be in “unsafe state” If a system is in safe state, deadlock can always be avoided If a system is in unsafe state, deadlock may not be avoided (deadlock will never happen even in the worst case) (deadlock can happen in the worst case)

19 CS 314 Operating Systems Deadlock_Avoidance/017 ProcessAssigned MAX. NeedRequests Pending Process Status ProcessAssigned MAX. Need B A C 2 3 2 4 9 7 B A C 2 3 2 4 9 7 The number of requests a process made, but not granted because OS does not have the requested resources Requests Pending Process Status If a process has at least one pending request, process is BLOCKED Otherwise a process is RUNNING 0 0 0 If a process gets all required resources then, the process becomes COMPLTED RUNNING

20 CS 314 Operating Systems ProcessAssigned MAX. NeedRequests Pending Process Status B A C 2 3 2 4 9 7 0 0 0 RUNNING Available 4 Assume: 11 instances of the resource R exist Deadlock_Avoidance/018

21 CS 314 Operating Systems ProcessAssigned MAX. NeedRequests Pending Process Status B A C 2 3 2 4 9 7 0 0 0 RUNNING Available 4 Assume: 11 instances of the resource R exist If Process A requests 4 more instances of this resource ProcessAssigned MAX. NeedRequests Pending Process Status B A C 2 3 2 4 9 7 0 4 0 RUNNING Available 4 0 0 7 0 This is “unsafe state” But Not Deadlock yet Deadlock_Avoidance/018

22 CS 314 Operating Systems ProcessAssigned MAX. NeedRequests Pending Process Status B A C 2 3 2 4 9 7 0 0 0 RUNNING Available 4 Assume: 11 instances of the resource R exist If Process A requests 1 more instances of this resource ProcessAssigned MAX. NeedRequests Pending Process Status B A C 2 2 4 9 7 0 1 0 RUNNING Available 0 0 7 BLOCKED Deadlock_Avoidance/019

23 CS 314 Operating Systems ProcessAssigned MAX. NeedRequests Pending Process Status B A C 2 3 2 4 9 7 0 0 0 RUNNING Available 4 Assume: 11 instances of the resource R exist If Process B requests 2 more instances of this resource ProcessAssigned MAX. NeedRequests Pending Process Status B A C 2 2 4 9 7 0 1 0 RUNNING Available 0 7BLOCKED 2 Deadlock_Avoidance/020

24 CS 314 Operating Systems ProcessAssigned MAX. NeedRequests Pending Process Status B A C 2 3 2 4 9 7 0 0 0 RUNNING Available 4 Assume: 11 instances of the resource R exist If Process C requests 2 more instances of this resource ProcessAssigned MAX. NeedRequests Pending Process Status B A C 2 2 4 9 7 1 0 RUNNING Available 0 7BLOCKED Now Deadlock 2 BLOCKED 2 Deadlock_Avoidance/021

25 CS 314 Operating Systems ProcessAssigned MAX. NeedRequests Pending Process Status B A C 2 3 2 4 9 7 0 0 0 RUNNING Available 4 Assume: 11 instances of the resource R exist If Process B requests 2 more instances of this resource ProcessAssigned MAX. NeedRequests Pending Process Status B A C 2 3 2 4 9 7 0 0 RUNNING Available 4 0 2 4 2 This is “safe state” 0 Deadlock_Avoidance/022

26 CS 314 Operating Systems ProcessAssigned MAX. NeedRequests Pending Process Status B A C 2 3 2 4 9 7 0 0 0 RUNNING Available 4 Assume: 11 instances of the resource R exist If Process B requests 2 more instances of this resource ProcessAssigned MAX. NeedRequests Pending Process Status B A C 3 2 9 7 0 0 0 0 RUNNING Available 6 0 This is “safe state” COMPLETED Deadlock_Avoidance/023


Download ppt "Deadlock Prevention & Avoidance Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki"

Similar presentations


Ads by Google