Operating Systems 2006/2007

Similar documents
Operating Systems 2010/2011

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

The Deadlock Problem (1)

Deadlocks. Dr. Yingwu Zhu

MODERN OPERATING SYSTEMS. Third Edition ANDREW S. TANENBAUM. Chapter 6 Deadlocks

Chapter 7: Deadlocks

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

CSE Opera+ng System Principles

The Deadlock Problem

Concurrency: Deadlock and Starvation. Chapter 6

System Model. Types of resources Reusable Resources Consumable Resources

Chapter 7: Deadlocks

What is Deadlock? Two or more entities need a resource to make progress, but will never get that resource. Examples from everyday life:

Chapter 8: Deadlocks

Chapter 8: Deadlocks. The Deadlock Problem. System Model. Bridge Crossing Example. Resource-Allocation Graph. Deadlock Characterization

Principles of Operating Systems

Deadlocks. Operating System Concepts - 7 th Edition, Feb 14, 2005

Last Class: Monitors. Real-world Examples

Last Class: Synchronization Problems!

Module 7: Deadlocks. The Deadlock Problem. Bridge Crossing Example. System Model

CS370 Operating Systems

VI. Deadlocks. What is a Deadlock? Intended Schedule. Deadlock Problem (1) ???

VI. Deadlocks Operating Systems Prof. Dr. Marc H. Scholl DBIS U KN Summer Term

OPERATING SYSTEMS. Deadlocks

Module 6: Deadlocks. Reading: Chapter 7

Deadlock. Concepts to discuss. A System Model. Deadlock Characterization. Deadlock: Dining-Philosophers Example. Deadlock: Bridge Crossing Example

ICS Principles of Operating Systems. Lectures Set 5- Deadlocks Prof. Nalini Venkatasubramanian

Deadlock Prevention. Restrain the ways request can be made. Mutual Exclusion not required for sharable resources; must hold for nonsharable resources.

The deadlock problem

Chapter 7: Deadlocks. Operating System Concepts 8 th Edition,

Chapter - 4. Deadlocks Important Questions

Chapter 7: Deadlocks. Chapter 7: Deadlocks. The Deadlock Problem. Chapter Objectives. System Model. Bridge Crossing Example

Chapter 7: Deadlocks. Operating System Concepts with Java 8 th Edition

Deadlocks. Deadlock Overview

Shared and Preemptable Resources. A few resources may be sharable. Anyone can write the system log.

Basics of Deadlock Theory. Deadlocks

Chapter 8: Deadlocks. The Deadlock Problem

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?

OPERATING SYSTEMS. Prescribed Text Book. Operating System Principles, Seventh Edition. Abraham Silberschatz, Peter Baer Galvin and Greg Gagne

Chapter 7: Deadlocks

Operating Systems: William Stallings. Starvation. Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall

CMSC 412. Announcements

Chapter 7 : 7: Deadlocks Silberschatz, Galvin and Gagne 2009 Operating System Concepts 8th Edition, Chapter 7: Deadlocks

Deadlock. Disclaimer: some slides are adopted from Dr. Kulkarni s and book authors slides with permission 1

Operating Systems. Deadlocks. Stephan Sigg. November 30, Distributed and Ubiquitous Systems Technische Universität Braunschweig

The Slide does not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams.

Last Class: Synchronization Problems. Need to hold multiple resources to perform task. CS377: Operating Systems. Real-world Examples

Chapter 7: Deadlocks. Operating System Concepts 8 th Edition,

CS420: Operating Systems. Deadlocks & Deadlock Prevention

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 7 Deadlocks. Zhi Wang Florida State University

Deadlocks. Prepared By: Kaushik Vaghani

Module 7: Deadlocks. The Deadlock Problem

Principles of Operating Systems

Module 7: Deadlocks. System Model. Deadlock Characterization. Methods for Handling Deadlocks. Deadlock Prevention. Deadlock Avoidance

Final Exam Review. CPSC 457, Spring 2016 June 29-30, M. Reza Zakerinasab Department of Computer Science, University of Calgary

DEADLOCKS M O D E R N O P E R A T I N G S Y S T E M S C H A P T E R 6 S P R I N G

Concurrency: Deadlock and Starvation

UNIT-5 Q1. What is deadlock problem? Explain the system model of deadlock.

Chapter 7: Deadlocks

Deadlocks. Copyright : University of Illinois CS 241 Staff 1

The Deadlock Problem

Deadlocks Prof. James L. Frankel Harvard University. Version of 7:05 PM 7-Mar-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

CS370 Operating Systems

Chapter 7: Deadlocks. Operating System Concepts 8 th Edition,! Silberschatz, Galvin and Gagne 2009!

Chapter 7: Deadlocks CS370 Operating Systems

CS370 Operating Systems

Resources. Lecture 4. Deadlocks. Resources (2) Resources (1) Four Conditions for Deadlock. Introduction to Deadlocks

CS370 Operating Systems

Introduction to Deadlocks

Operating Systems. Deadlocks

Resource Allocation and Deadlock Handling

Chapter 8: Deadlocks. Operating System Concepts with Java

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Deadlock. A Bit More on Synchronization. The Deadlock Problem. Deadlock Characterization. Operating Systems 2/7/2005. CSC 256/456 - Spring

Operating Systems. Deadlock. User OS. Kernel & Device Drivers. Interface Programs. Brian Mitchell - Operating Systems

Deadlock and Starvation

Deadlocks. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Deadlocks. Mehdi Kargahi School of ECE University of Tehran Spring 2008

Chapter 6 Concurrency: Deadlock and Starvation

The Deadlock Problem

Operating systems. Lecture 5. Deadlock: System Model. Deadlock: System Model. Process synchronization Deadlocks. Deadlock: System Model

Deadlock Prevention. CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han

Chapter 6 Concurrency: Deadlock and Starvation

COMPUTER SCIENCE 4500 OPERATING SYSTEMS

CSE 306/506 Operating Systems Deadlock. YoungMin Kwon

CISC 7310X. C10: Deadlocks. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 4/12/2018 CUNY Brooklyn College

Deadlocks. System Model

CMPT 300 Introduction to Operating Systems

Resource Management and Deadlocks 43

Chapter 3. Deadlocks

Chapter 3: Deadlocks

Chapter 7: Deadlocks. Operating System Concepts 8th Edition, modified by Stewart Weiss

Potential Deadlock Example

Operating Systems: Quiz2 December 15, Class: No. Name:

CSE 380 Computer Operating Systems

Operating Systems 2015 Spring by Euiseong Seo DEAD LOCK

CS307 Operating Systems Deadlocks

Deadlocks. Bridge Crossing Example. The Problem of Deadlock. Deadlock Characterization. Resource-Allocation Graph. System Model

CS307: Operating Systems

Operating Systems ECE344. Ding Yuan

Transcription:

Operating Systems 2006/2007 Blocking and locking Johan Lukkien 1

Blocking & locking Blocking: waiting for a certain condition to become true Starvation: unpredictable, even infinite blocking times the opposite of fairness the result of interference of scheduling and blocking typical, in real-time systems can be the result of cooperation of several processes e.g. the dining philosophers example perhaps in combination with a greedy scheduler happens through livelock or other forms of blocking Livelock repeated trying to pass a critical condition without making progress typically, associated with polling results functionally in starvation or deadlock Deadlock extreme case of starvation: continuation not possible typically, a cul-de-sac state of the system 2

Blocking times and scheduling Scheduling according to priority is problematic in view of non-preemptable shared resources inversion 3

Priority inversion A low priority task obtains a resource; a high priority task waits on it A middle priority task pre-empts the low priority task the high priority task now waits on the middle priority task... and executes effectively at the low priority high priority task waiting middle priority task executing high priority task waiting resource blocked by low priority task resource blocked by low priority task time time 4

Blocking times and scheduling Scheduling according to priority is problematic in view of non-preemptable shared resources inversion Solutions in resource acquiring policies priority inheritance while executing the critical section, do this with the highest priority of any waiting priority ceiling,... beyond our scope 5

Deadlock: terminology Deadlock is usually associated with access to resources consumable resources: resource use takes it away (variable number) typical producer / consumer problems reusable resources: resource is shared (fixed number) typical mutual exclusion problems (consumer and producer are same process), readers/writers problems Conditions for deadlock to be possible mutual exclusion hold and wait greediness, several resources of the same type as well as several of different types are reserved incrementally no preemption circular waiting... these all play a role and can be addressed explicitly in the solution i.e., deadlock is addressed by avoiding these conditions... however, deadlock is more general than these four as it may depend on general synchronization conditions (cf. condition synchronization) 6

Model for analysis We call a task (process or thread) blocked if: it is suspended on a blocking synchronization action or has terminated (for technical reasons included) Definition: a set D of tasks with at least one not terminated is called deadlocked if all tasks in D are blocked, and for each non-terminated task t in D, any task that might unblock it is also in D Notice: the relation may unblock introduces a dependency graph usually, the reverse is used: may be blocked on the releasing task induces the wait-for graph when blocking is related to reusable resources: resource dependency graph 7

Resource dependency graph Edges p R : p is acquiring R R p : p holds R p blocked: it has a (stable, not directly removable) outgoing arrow Graph analysis: reduction focus on the stable situation repeatedly remove a nonblocked process and all its incoming connections remaining set: deadlocked (contains a knot - strongly connected component) sufficient condition for deadlock for greedy allocation: existence of a knot in the original graph non-greedy allocation: acquisition can be defferred even if the resource is free (unlike semaphores!) 8

Reduction in progress... 9

Wait-for graph p1:... P(m); x := x+y; sigall (c); V(m)... p2:... P(m); x := a; sigall (c); V(m)... p3:... P(m); while x<0 do wait (m,c) od; x := x-1; b := true; signal (d); V(m)... p4:... P(m); while not b do wait (m, d) od;...b := false; V(m)... Same technique of reduction possibility of existence of the graph needs evidence e.g., if a is negative, there is never an arrow p2 p3 may label the arrows with corresponding conditions i.e., state information about the state when they occur 10

Dealing with deadlock Deadlock occurs infrequent because low probability of occurrence considered as a problem by programmers hence, most often solved Approaches Ignore timeouts external intervention Prevent (avoidance from programmer side) using the discussed design techniques Avoid (system side) dynamic checks Detect and recover 11

Prevention Make the reduced wait-graphs empty by construction Use the mentioned techniques prevent greediness, use fixed nesting (avoid circular wait), have terminating critical sections not always possible Use preemption of the resource when needed not always possible All resources at once (through condition synchronization) avoid the wait-and-hold greediness leads to possible starvation, see Philosophers Avoid cyclic dependencies (hence circular wait) extremely boring programs Prove correctness, typically by contraposition assume, a deadlock occurs, show a contradiction in principle: examine all possible combinations of blocking states in all tasks examine the corresponding wait-for graphs and show that these are not possible or not reachable examine the reachable states of the Finite State Machine corresponding to the request/acquisition sequences 12

State diagrams of p1 and p2 Example: state diagrams p2 reserves in opposite order than p1 Combined state diagram contains a reachable deadlocked state 13

Avoidance Maintain as an invariant that no deadlocked sets can occur upon each blocking action investigate if always an open execution path remains (system remains in a safe state) otherwise, deny the action or postpone completion Note: just make sure the reduced wait-graph is empty Postponement works if these blocking actions refer to resource allocations then we can compute the future states example: bankers algorithm need information about possible system behaviors in terms of resource requirements ( maximum numbers) requires separation between request and grant hence, no greediness in the granting! very difficult (impossible?) to extend to general condition synchronization needs information about the evolution and modification of variables Denial actually means detection (see later) 14

Bankers algorithm Given: set of N tasks set of R resources c[j] : number of type j resources max[i,j] : maximum number of type j resources task i needs Tasks acquire resources incrementally and release those eventually State av[j] : available type j resources alloc[i,j] : type j resources in use by task i claim[i,j] : maximum number type j resources to be claimed by task i initially, claim = max, av = 0, alloc = 0 Invariants:» av[j] = c[j] - ( i: : alloc[i,j])» claim [i,j] + alloc[i,j] = max[i,j] Requirement synchronize requests such that always each task can acquire resources until its specified maximum not having this represents a deadlock (potential? or guaranteed?) 15

(Maximum) claim graph Include the maximum claims as dashed arrows 16

Bankers algorithm Problem: while giving out resources arbitrarily a state may be reached such that no additional request can be served of some tasks (not enough left), ever hence these tasks can never proceed, and will also never give back their reservations... actually, an instance of wait-and-hold Solution: a state is called safe for a task if this task can be given its maximum number of resources eventually possibly by giving resources to other tasks first and then waiting until these release them again if that is not needed the state is called open for that task claim[i,j] <= Av[j], all j a state is called safe if it is safe for all tasks the initial state is safe (must be, what does this mean?) a new state (resulting from a request) is accepted only if it is safe now the problem reduces to verification of state safety 17

Example: avoiding deadlock Avoiding deadlock (a) to (b): give resource to p1 leaves a reducible graph could grant p3 s request as well (a) to (c): granting p2 s request leaves a non-reducible graph hence denied or postponed 18

State safety upon new request Assume a safe state Consider a new request by task i req[j] denotes the number of type j resources requested by task i The new state is obtained as follows av, alloc[i], claim[i] := av-req, alloc[i]+req, claim[i]-req It is enough to verify whether this new state is safe for just task i if it is, then eventually all its resources will be returned thus reaching an even safer state than the one before the adjustment Task i is safe when its claims can be satisfied, either directly or by completing any of the other tasks (this must be verified) Note: we use vector and matrix addition, vector comparison and assignment with the 0 vector all interpreted componentwise completing the open tasks corresponds to the graph reduction mentioned before 19

Algorithm func NextOpen (Av: Vector; Claim, Alloc: Matrix): int { returns index of first open and contributing state } [ for i := 0 to N-1 do if Alloc[i] <> 0 and Claim[i] <= Av then return(i) fi od; return (N) ] ; func Safe (Av: Vector; Claim, Alloc: Matrix; req: Vector; i: int): bool { return whether the parameters encode a new safe state precondition: Av <= Req } [ var k: int; Av, Alloc[i], Claim[i] := Av-req, Alloc[i]+req, Claim[i]-req; { determine new state } k := NextOpen (Av, Claim, Alloc); while k <> N and not (Claim[i] <= Av) { open tasks left and i itself is not open in current state } do Av, Alloc[k], Claim[k] := Av+Alloc[k], 0, Max[k]; { assume open task k completes } k := NextOpen (Av, Claim, Alloc); od; return (Claim[i] <= Av); ] 20

Detection Incremental upon each blocking action investigate if a deadlock occurs if so, deny the action this may be too late though, roll-back may be needed example: verification of semaphore nesting Repeatedly, monitoring the system overhead Need to deal with the error locally, inside the task that tried blocking globally, through a recovery policy kill all selectively, based on criteria, like priority, progress made etc. roll back to safe state works only if alternatives exist need recording checkpoints, i.e., enough history information to restart preempt resources, if possible based on certain criteria however, one may argue that the deadlock does not exist in this case 21

Strategy depends on resource type Swap space in secondary memory reserve all, or avoidance Process resources: files, printers,... require declaration ahead of time use avoidance Main memory prevention through preemption see swap space if preemption is not possible Internal, shared resources (i/o ports, shared memory segments) prevention through ordering 22

Overview (Stallings) additional starvation 23