The Banker’s Algorithm for A Single Resource

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Operating Systems Lecture Notes Deadlocks Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Synchronization Algorithms and Concurrent Programming
Deadlocks Today Resources & deadlocks Dealing with deadlocks Other issues Next Time Memory management.
EEE 435 Principles of Operating Systems Deadlock Avoidance, Prevention, and Wrap-Up (Modern Operating Systems 3.5, 3.6, and 3.7)
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
5/25/2015Page 1 Deadlock Management B. Ramamurthy.
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.
DPNM Lab. Dept. of CSE, POSTECH
Deadlock Chapter 3 R1 R2 P2P1 Allocated Requested.
CSC 322 Operating Systems Concepts Lecture - 29: by
Deadlocks Tore Larsen With slides from T. Plagemann, C. Griwodz, K. Li, A. Tanenbaum and M. van Steen.
1 CS 333 Introduction to Operating Systems Class 7 - Deadlock Jonathan Walpole Computer Science Portland State University.
1 Wednesday, June 28, 2006 Command, n.: Statement presented by a human and accepted by a computer in such a manner as to make the human feel that he is.
Concurrency: Deadlock & Starvation
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Deadlock Detection with One Resource of Each Type (1)
1 Concurrency: Deadlock and Starvation Chapter 6.
Chapter 6 Concurrency: Deadlock and Starvation
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
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.
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.
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.
1 Pertemuan 10 Deadlock (lanjutan) Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5.
Operating Systems 软件学院 高海昌 Operating Systems Gao Haichang, Software School, Xidian University 22 Contents  1. Introduction** 
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.
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
Deadlocks System Model RAG Deadlock Characterization
CS333 Intro to Operating Systems Jonathan Walpole.
Styresystemer og Multiprogrammering Block 3, 2005 Deadlocks Robert Glück.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings.
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!
Sistem Operasi IKH311 Deadlock. 2 Resources Examples of computer resources printers tape drives tables Processes need access to resources in reasonable.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Concurrency: Deadlock and Starvation
Deadlock Management.
Operating System: DEADLOCKS
Chapter 7 Deadlock.
Lecture 19: Deadlock: Conditions, Detection and Avoidance
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.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
CS 333 Introduction to Operating Systems Class 7 - Deadlock
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Chapter 7: 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
Presentation transcript:

The Banker’s Algorithm for A Single Resource Granting the request leads to an unsafe state? True: deny the request False: carry the request out Has Max A 6 B 5 C 4 D 7 Has Max A 1 6 B 5 C 2 4 D 7 Has Max A 1 6 B 2 5 C 4 D 7 Free: 10 Free: 2 Free: 1 Safe Safe Unsafe!

Dealing With Multiple Resources Tape drives Scanners CD ROMs Process Plotters Tape drives Scanners CD ROMs Process Plotters E=(6 3 4 2) A=(1 0 2 0) P=(5 3 2 2) E=A+P A 3 1 B C D E A 1 B 2 C 3 D E C: Resources assigned R: Resources still needed

Algorithm Find a row (process) in R whose unmet resource needs are all smaller than or equal to A No such row  the system will possibly deadlock (unsafe) Mark the process as terminated, add all its resources to the A vector Repeat 1 and 2 until either all process are marked terminated (safe state), or until a deadlock occurs (unsafe state)

Problem of Deadlock Avoidance Wonderful algorithm in theory Essentially useless in practice Can you tell in advance what your maximum resource need for running your browser is? Number of process is dynamic Resources can break Information about future requests is unknown! Kind of familiar?

Outline Resources and deadlock The ostrich algorithm Deadlock detection and recovery Deadlock avoidance Deadlock prevention Related issues

Deadlock Avoidance Vs. Prevention Avoidance (a police directing traffic) The system dynamically consider every request and decides if it is safe to grant it at this point Allow more concurrency Prevention (a red traffic light) Constrain how requests for resources can be made and how they are handled Ensure at least one of the necessary conditions for deadlock cannot hold. Four necessary conditions for a deadlock: mutual exclusion, hold and wait, no preemption and circular wait

Eliminate Mutual Exclusion Spooling technique Good for printer, plotter, etc. Only printer daemon can access the physical printer and it requires no other resource. Not all resources can be spooled. Examples? Competition on spooling space Daemon only prints after the complete output file is available. General idea to reduce deadlocks Assign a resource only when it is absolutely necessary As few processes as possible may actually claim the resource

Break Hold And Wait Condition Request all resources before execution Resource requirement is unclear before execution Inefficient usage of resources Used in some mainframe batch systems Much more instances of each I/O device Many jobs are CPU-bound Improvement: when requesting a new resource, temporarily release all resource, then request all at once

Destroy Circular Wait One process at most one resource at any moment Must release the first one when requiring the second one. How to copy a huge file from a tape to a printer? Global numbering of all resources Processes request resources in numerical order Hard to find an order good for everyone Different systems may have different orders  a program may have to be modified before it runs! RAG i A j B 1. Scanner 2. Plotter 3. Tape driver 4. CD-ROM driver 1-2-3 OK! 1-4-3 illegal! i<j, B not allowed to require i i>j, A not allowed to require j

Approaches to Deadlock Prevention Condition Approach Mutual exclusion Spooling Hold and wait Request all resources before execution No preemption Take resources away Circular wait Order resources numerically

Outline Resources and deadlock The ostrich algorithm Deadlock detection and recovery Deadlock avoidance Deadlock prevention Related issues

Two-phase Locking in Databases An excellent special purpose algorithm Scenario: lock on several records, update all of them and release. Phase I: try to lock all the records it needs, one at a time If succeed (get all the records), go to Phase II Else, release all locks, start Phase I again Problems? Refer to dining philosophers problem Phase II: do updates, release the locks Not a general strategy No process pending/start over in real-time system Many operations cannot be safely repeated.

Starvation Deadlock free is not enough for OS No starvation: make sure each process getting service. Example: allocation of CPU Shortest job first: maximize throughput Long job may starve to death in a busy system! First-come-first-serve: fair, no starvation Lower throughput

Summary Deadlock: all processes are blocked and no progress can be made Mutual exclusion Hold and wait No preemption Circular wait Deadlock detection & recovery, avoidance, and prevention