Deadlock Prevention & Avoidance

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Chapter 5 Deadlocks. Contents What is deadlock? What is deadlock? Characterization Characterization Resource allocation graph Resource allocation graph.
1 Concurrency: Deadlock and Starvation Chapter 6.
Deadlock Prevention, Avoidance, and Detection
Lecture 6 :Deadlocks. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other Involves.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Deadlock Prevention, Avoidance, and Detection.  The Deadlock problem The Deadlock problem  Conditions for deadlocks Conditions for deadlocks  Graph-theoretic.
Lecture 7: Deadlock     Necessary Conditions for Deadlock     Deadlock Prevention - Havender's Linear Ordering Deadlock Avoidance Deadlock Detection &
Ceng Operating Systems Chapter 2.4 : Deadlocks Process concept  Process scheduling  Interprocess communication  Deadlocks Threads.
EEE 435 Principles of Operating Systems Deadlock Avoidance, Prevention, and Wrap-Up (Modern Operating Systems 3.5, 3.6, and 3.7)
Chapter 3 Deadlocks TOPICS Resource Deadlocks The ostrich algorithm
DPNM Lab. Dept. of CSE, POSTECH
CSC 322 Operating Systems Concepts Lecture - 29: by
Deadlocks. 2 System Model There are non-shared computer resources –Maybe more than one instance –Printers, Semaphores, Tape drives, CPU Processes need.
The Banker’s Algorithm for A Single Resource
Deadlock CSCI 444/544 Operating Systems Fall 2008.
The ‘deadlock’ conditions Reviewing some key points concerning the potential for ‘deadlock’ in an operating system.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
Deadlock Characterization
CH 3 Deadlock When 2 (or more) processes remain blocked forever!
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-6 Deadlocks Department of Computer Science and Software Engineering.
Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department.
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
Operating Systems (CS 340 D) Dr. Abeer Mahmoud Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
CS333 Intro to Operating Systems Jonathan Walpole.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Chapter 8 Deadlocks. Objective System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection.
Deadlock. Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Deadlocks.
Deadlocks 12/02/2015. What is a deadlock ? System has a finite set of resources. Resource can have one or more instances. Processes compete for resources.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.
CH 3 Deadlock When 2 (or more) processes remain blocked forever!
Deadlock Prevention & Avoidance Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki
Deadlocks CPE Operating Systems
Chapter 7 Deadlocks 1. Objectives and Outline Outline The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock.
Lecture 6 Deadlock 1. Deadlock and Starvation Let S and Q be two semaphores initialized to 1 P 0 P 1 wait (S); wait (Q); wait (Q); wait (S);. signal (S);
Deadlock Operating Systems (CC2011NI) -Mr. Pranoy Man Pradhan.
Deadlock. Examples You can't get a job without experience; you can't get experience without a job. A set of blocked processes each holding a resource.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Process Management Deadlocks.
Operating Systems, Summer Semester 2011
Operating Systems, Winter Semester 2011
Deadlock Management.
ITEC 202 Operating Systems
Chapter 6 : Deadlocks What is a Deadlock?
Operating Systems (CS 340 D)
Operating System: DEADLOCKS
OPERATING SYSTEMS DEADLOCKS
Lecture 19: Deadlock: Conditions, Detection and Avoidance
Chapter 7 Deadlocks.
Process Deadlocks.
Deadlocks Definition A set of processes is in a Deadlock state when every process in the set is waiting for an event that can only be caused by another.
Deadlocks Peng Lu In a multiprogramming environment, several processes may compete for a finite number of resources. A process requests resources; if the.
The relation between the process and
Deadlocks Session - 13.
DEADLOCK.
Lecture 27 Syed Mansoor Sarwar
Deadlock Hank Levy 1.
Lecture 19: Deadlock: Conditions, Detection and Avoidance
Uniprocessor Process Management & Process Scheduling
OPERATING SYSTEMS DEADLOCKS.
Deadlock Prevention & Avoidance
IT3002 Computer Architecture
Deadlock A deadlock situation on a resource can arise if and only if all of the following conditions hold simultaneously in a system: Mutual exclusion.
OPERATING SYSTEMS DEADLOCKS.
DEADLOCKS.
Introduction to Deadlocks
Process Synchronization
Presentation transcript:

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

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

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

CS 314 Operating Systems 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 holds some 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 Deadlock_Avoidance/003

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

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

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

CS 314 Operating Systems 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 X1 Y2 Z3 Request (X, Y, Z) (Y, Z) A B Deadlock_Avoidance/007

CS 314 Operating Systems 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 X1 Y2 Z3 Assigned (X, Y, Z) A B Request (Y, Z) Deadlock_Avoidance/008

CS 314 Operating Systems 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 X1 Y2 Z3 Assigned (X, Y, Z) A B Assigned (Y, Z) Request Deadlock_Avoidance/009

CS 314 Operating Systems 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 X1 Y2 Z3 Assigned Deadlock A B Assigned Requested (X, Y, Z) (Y, Z) Requested Assigned Deadlock_Avoidance/010

CS 314 Operating Systems 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 X1 Y2 Z3 Assigned Process B blocks Assigned Request (X, Y, Z) A B (Y, Z) Request Deadlock_Avoidance/011

CS 314 Operating Systems 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 X1 Y2 Z3 Assigned Process B blocks Process A Completes A B Assigned Request (X, Y, Z) (Y, Z) Assigned Deadlock_Avoidance/012

CS 314 Operating Systems 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 X1 Y2 Z3 Request B (Y, Z) Deadlock_Avoidance/013

CS 314 Operating Systems 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 X1 Y2 Z3 Assigned B (Y, Z) Requested Deadlock_Avoidance/014

CS 314 Operating Systems 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 X1 Y2 Z3 Process B completes Assigned B (Y, Z) Assigned Deadlock_Avoidance/015

CS 314 Operating Systems 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”) Deadlock_Avoidance/016

CS 314 Operating Systems The two states defined in Deadlock Avoidance  Safe State  Unsafe State 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 (deadlock will never happen even in the worst case) If a system is in safe state, deadlock can always be avoided If a system is not in safe state, the system must be in “unsafe state” (deadlock can happen in the worst case) If a system is in unsafe state, deadlock may not be avoided Deadlock_Avoidance/016

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

CS 314 Operating Systems Assume: 11 instances of the resource R exist Process Assigned MAX. Need Requests Pending Process Status Available B A C 2 3 4 9 7 RUNNING 4 RUNNING RUNNING Deadlock_Avoidance/018-A

CS 314 Operating Systems Assume: 11 instances of the resource R exist Process Assigned MAX. Need Requests Pending Process Status Available B A C 2 3 4 9 7 RUNNING 4 RUNNING RUNNING But Not Deadlock yet If Process A requests 4 more instances of this resource Process Assigned MAX. Need Requests Pending Process Status Available B A C 3 4 9 7 4 BLOCKED RUNNING 4 2 RUNNING 2 RUNNING Deadlock_Avoidance/018-B

CS 314 Operating Systems Assume: 11 instances of the resource R exist Deadlock = all (3) processes blocked waiting for additional resource Process Assigned MAX. Need Requests Pending Process Status Available B A C 2 3 4 9 7 RUNNING 4 RUNNING RUNNING Unsafe state = no one can complete if no one releases resource If Process A requests 4 more instances of this resource This is “unsafe state” Process Assigned MAX. Need Requests Pending Process Status Available B A C 7 3 4 9 7 4 RUNNING BLOCKED 4 2 RUNNING 2 RUNNING But Not Deadlock yet Deadlock_Avoidance/018-C

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

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

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

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

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

Process Assigned MAX. Need Requests Pending Process Status B A C 2 4 7 14 5 RUNNING Available 6