Operating Systems COMP 4850/CISG 5550 Deadlocks Dr. James Money.

Slides:



Advertisements
Similar presentations
Advanced Operating Systems
Advertisements

1 Concurrency: Deadlock and Starvation Chapter 6.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Lecture 6 :Deadlocks. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other Involves.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Deadlocks Today Resources & deadlocks Dealing with deadlocks Other issues Next Time Memory management.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Operating Systems COMP 4850/CISG 5550 Deadlock Avoidance Dr. James Money.
Chapter 3 Deadlocks TOPICS Resource Deadlocks The ostrich algorithm
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
Tanenbaum Ch 6 Silberschatz Ch 7
Chapter 3 Deadlocks - Αδιέξοδα 3.1. Resource
With slides from C. Griwodz, K. Li, A. Tanenbaum and M. van Steen
Avishai Wool lecture Introduction to Systems Programming Lecture 5 Deadlocks.
Deadlock Chapter 3 R1 R2 P2P1 Allocated Requested.
Deadlocks Tore Larsen With slides from T. Plagemann, C. Griwodz, K. Li, A. Tanenbaum and M. van Steen.
Deadlocks. 2 System Model There are non-shared computer resources –Maybe more than one instance –Printers, Semaphores, Tape drives, CPU Processes need.
Deadlock CSCI 444/544 Operating Systems Fall 2008.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
DeadlocksDeadlocks CS Imagine a narrow set of stairs, only wide enough for one person to pass. However, the landings are big enough for several.
1 Concurrency: Deadlock and Starvation Chapter 6.
Chapter 6 Deadlocks Resources Introduction Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Deadlocks CS 342 – Operating Systems Ibrahim Korpeoglu Bilkent University.
Deadlocks.
Deadlock Chapter 3 Thursday, February 22, Today’s Schedule Assignment #4 from Chapter 3 posted Deadlock - Chapter 3  Skip multiple resources (3.4.2.
1 Processes, Threads, Race Conditions & Deadlocks Operating Systems Review.
CH 3 Deadlock When 2 (or more) processes remain blocked forever!
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
Chapter 7 – Deadlock (Pgs 283 – 306). Overview  When a set of processes is prevented from completing because each is preventing the other from accessing.
Overview Resources Why do deadlocks occur? Dealing with deadlocks Ignoring them: ostrich algorithm Detecting & recovering from deadlock Avoiding deadlock.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance 3.6. Deadlock prevention.
1 Deadlocks 2 Resources Examples of computer resources –printers –tape drives –tables Processes need access to resources in reasonable order Suppose.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
1 Deadlocks Chapter 3. 2 Resources Examples of computer resources –printers –tape drives –tables Processes need access to resources in reasonable order.
Operating Systems 软件学院 高海昌 Operating Systems Gao Haichang, Software School, Xidian University 22 Contents  1. Introduction** 
Operating Systems Part III: Process Management (Deadlocks)
1 Deadlock Definition of deadlock Condition for its occurrence Solutions for avoiding and breaking deadlock –Deadlock Prevention –Deadlock Avoidance –Deadlock.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
Operating Systems (OS)
1 MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
CIS Operating Systems Deadlock Professor Qiang Zeng Fall 2015.
CSC 322 Operating Systems Concepts Lecture - 28: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
CS333 Intro to Operating Systems Jonathan Walpole.
Deadlocks.  Deadlocks: Occurs when threads are waiting for resources with circular dependencies Often involve nonpreemptable resources, which cannot.
Chapter 8 Deadlocks. Objective System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection.
CH 3 Deadlock When 2 (or more) processes remain blocked forever!
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. 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.
Sistem Operasi IKH311 Deadlock. 2 Resources Examples of computer resources printers tape drives tables Processes need access to resources in reasonable.
Deadlocks Lots of resources can only be used by one process at a time. Exclusive access is needed. Suppose process A needs R1 + R2 and B needs R1 + R2.
Process Management Deadlocks.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Concurrency: Deadlock and Starvation
ITEC 202 Operating Systems
CS703 - Advanced Operating Systems
Lecture 19: Deadlock: Conditions, Detection and Avoidance
CS 333 Introduction to Operating Systems Class 7 - Deadlock
DPNM Lab. Dept. of CSE, POSTECH
Review: Readers-Writers Problem
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Lecture 19: Deadlock: Conditions, Detection and Avoidance
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Introduction to Deadlocks
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Chapter 3 Deadlocks -For MCA, PU
Presentation transcript:

Operating Systems COMP 4850/CISG 5550 Deadlocks Dr. James Money

Deadlocks Computer contain many resources Computer contain many resources –Some can be shared –The rest cannot be shared Examples of non-shared resources are Examples of non-shared resources are –Printers –Tape drives –Special memory addresses –File access

Deadlocks Example: Printing Example: Printing –Imagine if two processes had access to the printer simultaneously –One line might from process one –The second might be from process two –And repeating… Solution: grant temporary exclusive access to a shared resource Solution: grant temporary exclusive access to a shared resource

Deadlocks Many times, processes need access to 2+ resources at the same time Many times, processes need access to 2+ resources at the same time Two processes are scanning a document and writing it to CD Two processes are scanning a document and writing it to CD First process scans, then tries to write to CD First process scans, then tries to write to CD Second process locks the CD first, then tries to scan Second process locks the CD first, then tries to scan Both processes block! This is called a deadlock. Both processes block! This is called a deadlock.

Deadlocks Same situation can occur across multiple machines as well Same situation can occur across multiple machines as well Many times on a network, these same devices are shared and the same problem occurs Many times on a network, these same devices are shared and the same problem occurs It may involve 3,4,5+ users and machines It may involve 3,4,5+ users and machines

Resources Deadlocks occur when processes exclusive access to devices, file, etc. Deadlocks occur when processes exclusive access to devices, file, etc. To simplify, we refer to any object that can grant exclusive access as a resource. To simplify, we refer to any object that can grant exclusive access as a resource. In a given computer system there are 10s- 100s resources to be managed. In a given computer system there are 10s- 100s resources to be managed.

Preemptable and Nonpreemptable Resources There are two types of resources: There are two types of resources: –Preemptable – resource that can be taken away from a process without any ill effects Memory Memory Usually does not cause deadlocks Usually does not cause deadlocks –Nonpreemtable – resource that cannot be taken away from a process without having a computation fail CD Writer CD Writer We focus on this for deadlocks We focus on this for deadlocks

Resources The sequence to use a resource is: The sequence to use a resource is: –Request the resource –Use the resource –Release the resource If the resource is not available when requesting, the process is forced to wait, either: If the resource is not available when requesting, the process is forced to wait, either: –Blocking –Returns an error code and process tries again later

Resource Acquisition For some resources, such as a database system, the user process can manage the resources For some resources, such as a database system, the user process can manage the resources One way is to use a semaphore, as in critical regions One way is to use a semaphore, as in critical regions

Resource Acquisition typedef int semaphore; semaphore resource1; void processA(void){ down(&resource1);use_resource1();up(&resource1);}

Resource Acquisition – 2 Resources typedef int semaphore; semaphore resource1; semaphore resource2; void processA(void){ down(&resource1);down(&resource2);usebothresources();up(&resource1);up(&resource2);}

Resource Acquisition Only one process involved so far Only one process involved so far What happens when we go to two processes? What happens when we go to two processes?

Resource Acquisition typedef int semaphore; semaphore resource1; semaphore resource2; void processA(void){ down(&resource1);down(&resource2);usebothresources();up(&resource2);up(&resource1);} void processB(void){ down(&resource1);down(&resource2);usebothresources();up(&resource2);up(&resource1);}

Resource Acquisition typedef int semaphore; semaphore resource1; semaphore resource2; void processA(void){ down(&resource1);down(&resource2);usebothresources();up(&resource2);up(&resource1);} void processB(void){ down(&resource2);down(&resource1);usebothresources();up(&resource1);up(&resource2);}

Introduction to Deadlocks Deadlocks are formally defined by Deadlocks are formally defined by –A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause Since they are all waiting, none of them will wake up Since they are all waiting, none of them will wake up Assumption of no interrupts and single threads Assumption of no interrupts and single threads

Conditions for Deadlock 1. Mutual Exclusion – each resource is either currently assigned to one process or is available 2. Hold and Wait – processes currently holding resources can request new resources 3. No preemption – Resources previously granted cannot forcibly be taken away from the process. They must be released by the process 4. Circular Wait – there must be a circular chain of 2+ processes, each whom is waiting for a resource held by the next member of the chain

Conditions for Deadlock All four conditions must exist for a deadlock to occur All four conditions must exist for a deadlock to occur If one is absent, deadlock cannot occur If one is absent, deadlock cannot occur Many of these are related to system policy choices Many of these are related to system policy choices

Deadlock Modeling Holt showed in 1972 that the four conditions could be modeled using direct graphs Holt showed in 1972 that the four conditions could be modeled using direct graphs The graphs have two types of nodes: The graphs have two types of nodes: –Processes – shown as circles –Resources – shown as squares

Deadlock Modeling The arc from process to graph and vice versa determines if the resource is held or being waited on: The arc from process to graph and vice versa determines if the resource is held or being waited on: –An arc from a resource (square) to a process (circle) indicates the resource is held by that process –An arc from a process to a resource indicates the process is blocked waiting for the resource

Deadlock Modeling

Dealing with Deadlocks Ignore the problem, maybe it will ignore you? Ignore the problem, maybe it will ignore you? –Used by UNIX and Windows Detection and Recovery Detection and Recovery Dynamic avoidance by careful resource allocation Dynamic avoidance by careful resource allocation Prevention by structurally negating one of the four conditions for deadlocks Prevention by structurally negating one of the four conditions for deadlocks

Ostrich Algorithm Here we stick our head in the sand like an ostrich and pretend there is no problem Here we stick our head in the sand like an ostrich and pretend there is no problem Different reactions Different reactions –Mathematicians say it is unacceptable and must be prevented all costs –Engineers might ask how often does it really occur and how serious the situation is

Ostrich Algorithm Most operating systems suffer from this approach Most operating systems suffer from this approach Example: Unix Process table Example: Unix Process table –Fixed length and finite –If fork() fails because the table is full, program waits and tries again (/bin/login does this, for example)

Ostrich Algorithm However, consider this: However, consider this: Assume 100 process table slots Assume 100 process table slots Ten programs run that need to create 12 sub-processes each Ten programs run that need to create 12 sub-processes each After each program creates 9 processes, the table is full After each program creates 9 processes, the table is full No process finishes because it keeps trying to fork! No process finishes because it keeps trying to fork!

Ostrich Algorithm Do we abandon the processes and the fork calls? Do we abandon the processes and the fork calls? Similar to this is the maximum number of open files, which is restricted by the size of the i-node table Similar to this is the maximum number of open files, which is restricted by the size of the i-node table The solution is not obvious or easy, which is why most operating systems choose this approach The solution is not obvious or easy, which is why most operating systems choose this approach