Process Synchronisation (contd.) Deadlock. Operating Systems. Spring CS5212

Similar documents
Deadlock. Operating Systems. Autumn CS4023

The Deadlock Problem. A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.

Process Synchronisation (contd.) Operating Systems. Autumn CS4023

Chapter 8: Deadlocks. The Deadlock Problem

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

Deadlocks. Minsoo Ryu. Real-Time Computing and Communications Lab. Hanyang University.

The Deadlock Problem

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

Chapter 7: Deadlocks

Chapter 8: Deadlocks

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

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

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

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

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

Module 7: Deadlocks. The Deadlock Problem

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

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

Chapter 8: Deadlocks. The Deadlock Problem

Lecture 7 Deadlocks (chapter 7)

Chapter 7: Deadlocks

Maximum CPU utilization obtained with multiprogramming. CPU I/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait

Chapter 7: Deadlocks

Principles of Operating Systems

Chapter 8: Deadlocks. Bridge Crossing Example. The Deadlock Problem

Lecture 3: Synchronization & Deadlocks

Chapter 7: Deadlocks

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

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

Principles of Operating Systems

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

Deadlocks. Deadlock Overview

CS307: Operating Systems

Chapter 8: Deadlocks. Operating System Concepts with Java

System Model. Types of resources Reusable Resources Consumable Resources

Bridge Crossing Example

Deadlocks. Prepared By: Kaushik Vaghani

Deadlock Risk Management

CHAPTER 7: DEADLOCKS. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

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

Process Synchronization

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

CS307 Operating Systems Deadlocks

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

The Deadlock Problem (1)

CSE Opera+ng System Principles

Deadlock and Starvation

CMSC 412. Announcements

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition

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

Chapter 6: Process Synchronization

Process Synchronization

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

The Deadlock Problem

Chapter 6: Synchronization. Operating System Concepts 8 th Edition,

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

Synchronization. Race Condition. The Critical-Section Problem Solution. The Synchronization Problem. Typical Process P i. Peterson s Solution

Chapter 6: Process Synchronization

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Process Synchronization: Semaphores. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6.

CS420: Operating Systems. Deadlocks & Deadlock Prevention

COMP 3713 Operating Systems Slides Part 3. Jim Diamond CAR 409 Jodrey School of Computer Science Acadia University

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

CS370 Operating Systems

Unit-03 Deadlock and Memory Management Unit-03/Lecture-01

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Synchronization Principles

Module 6: Process Synchronization. Operating System Concepts with Java 8 th Edition

Chapter 8: Deadlocks. The Deadlock Problem

Chapter 6: Process Synchronization. Module 6: Process Synchronization

Deadlocks. Dr. Yingwu Zhu

CS370 Operating Systems

More on Synchronization and Deadlock

Silberschatz, Galvin and Gagne 2013! CPU cycles, memory space, I/O devices! " Silberschatz, Galvin and Gagne 2013!

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Chapter 7: Deadlocks. Operating System Concepts 9th Edition DM510-14

Operating Systems 2015 Spring by Euiseong Seo DEAD LOCK

The Deadlock Problem

Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - X Deadlocks - I. University at Buffalo. Synchronization structures

Roadmap. Problems with Semaphores. Semaphores. Monitors. Monitor - Example. Tevfik Koşar. CSE 421/521 - Operating Systems Fall 2012

Deadlocks. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Deadlock Risk Management

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

Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - XI Deadlocks - II. University at Buffalo. Deadlocks. October 6 th, 2011

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

Lesson 6: Process Synchronization

Process Synchronization

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

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

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

Deadlocks. The Deadlock Problem. Bridge Crossing Example. Topics

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

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

CHAPTER 7 - DEADLOCKS

Last Class: Monitors. Real-world Examples

IV. Process Synchronisation

Transcription:

Operating Systems Spring 2009-2010

Outline Process Synchronisation (contd.) 1 Process Synchronisation (contd.) 2

Announcements Presentations: will be held on last teaching week during lectures make a 20-minute presentation additionally, a publicly available.pdf of talk 5 teams of 2 topic: smartphone operating systems Symbian Google / Android iphone Blackberry Windows Mobile

Solution to Critical-Section Problem Any design solution to the critical section problem must address Mutual Exclusion: If process P i is executing in its critical section, then no other processes can be executing in their critical sections Progress: If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indefinitely Bounded Waiting: A bound must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted Assume that each process executes at a nonzero speed No assumption concerning relative speed of the N processes

Petersen s Solution Two process solution Assume that the LOAD and STORE instructions are atomic; that is, cannot be interrupted. This is not reasonable on modern CPUs! The two processes share two variables: int turn; boolean flag[2] The variable turn indicates whose turn it is to enter the critical section The boolean array flag is used to indicate if a process is ready to enter the critical section: flag[i]=true implies that process P i is ready!

Petersen s Solution (contd.) Two processes, P 0 and P 1 ; code below is for process P i ; other process is j = 1 i; Algorithm for Process P i while (true) { flag[i] = true; turn = j; // j = 1-i while ( flag[j] && turn == j) /* no-op */ ; CRITICAL SECTION flag[i] = false; REMAINDER SECTION }

Synchronization Hardware Many systems provide hardware support for critical section code Could disable interrupts ( uniprocessor ) Currently running code would execute without preemption Generally too inefficient on multiprocessor systems: OSs using this are not broadly scalable Modern machines provide special atomic hardware instructions Either test memory word and set value Or swap contents of two memory words

Semaphores Synchronization tool that does not require busy waiting Semaphore S, an integer variable Two standard operations modify S: wait() and signal() Originally called P() and V() (from the Dutch) Less complicated Can only be accessed via two indivisible (atomic) operations whose implementation are: wait(s): wait(s) { while (S <= 0) ; // no-op S- -; } signal(s): Signal(S) { S++; }

Semaphores as a General Synchronization Tool Counting semaphore: integer value which can range over an unrestricted domain (permits more than one simultaneous access) Binary semaphore: integer value can range only between 0 and 1 can be simpler to implement Also known as a mutex lock Can implement a counting semaphore S as a binary semaphore Provides mutual exclusion Semaphore S; // initialized to 1 wait(s); CRITICAL SECTION signal(s);

Semaphore Implementation Must guarantee that no two processes can execute wait() and signal() on the same semaphore at the same time Thus, implementation becomes the critical section problem where the wait and signal code are placed in the critical section Could now have busy waiting in critical section implementation But implementation code is short Little busy waiting if critical section rarely occupied Conversely, applications which spend lots of time in critical sections should not use this implementation

Semaphore Implementation with no Busy Waiting With each semaphore there is an associated waiting queue. Each entry in a waiting queue has two data items: int value pointer to next record in the list Two operations: block: place the process invoking the operation on the appropriate waiting queue wakeup: remove one of processes in the waiting queue and place it in the ready queue

Outline Process Synchronisation (contd.) 1 Process Synchronisation (contd.) 2

The Problem A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set Example: System has 2 disk drives P1 and P2 each hold one disk drive and each needs another one Example semaphores A and B, initialized to 1 P 0 wait(a); wait(b); P 1 wait(b); wait(a);

The Problem (contd.) Bridge Crossing Example: Traffic only in one direction Each section of a bridge can be viewed as a resource If a deadlock occurs, it can be resolved if one car backs up (preempt resources and rollback) Several cars may have to be backed up if a deadlock occurs Starvation is possible

System Model Process Synchronisation (contd.) Resource types R 1, R 2,..., R m (CPU cycles, memory space, I/O devices) Each resource type R i has W i instances Each process utilizes a resource as follows: request use release

Characterization can only arise if four conditions hold simultaneously: Mutual exclusion: only one process at a time can use a resource Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task Circular wait: there exists a set {P 0, P 1,..., P n } of waiting processes such that P 0 is waiting for a resource that is held by P 1, P 1 is waiting for a resource that is held by P 2,..., P n 1 is waiting for a resource that is held by P n, and P n is waiting for a resource that is held by P 0

Resource-Allocation Graph A set of vertices V and a set of edges E V is partitioned into two types: P = {P 1, P 2,..., P n }, the set consisting of all the processes in the system R = {R 1, R 2,..., R m }, the set consisting of all resource types in the system request edge: a directed edge P i R j assignment edge: a directed edge R k P l

Example of a Resource-Allocation Graph Three processes, P 1, P 2 and P 3 Four resources Two instances of resource R 2 Three instances of resource R 4 Process P 1 has been allocated one instance of R 2 and has requested an instance of R 1 Process P 2 has been allocated one instance of R 2 and has requested an instance of R 3 etc.

Resource-Allocation Graph with. Process P 3 requests an instance of R 2

Detection If graph contains no cycles then there is no deadlock If graph contains a cycle: if only one instance per resource type, then deadlock if several instances per resource type, then possibility of deadlock

Resource-Allocation Graph with possibility of

Methods for Handling s Ensure that the system will never enter a deadlock state Allow the system to enter a deadlock state and then recover Ignore the problem and pretend that deadlocks never occur in the system; used by most operating systems, including UNIX

Prevention Restrain the ways request can be made. Mutual Exclusion: not required for sharable resources; must hold for nonsharable resources Hold and Wait: must guarantee that whenever a process requests a resource, it does not hold any other resources Require process to request and be allocated all its resources before it begins execution, or allow process to request resources only when the process has none Low resource utilization; starvation possible.

Prevention (contd.) No Preemption: If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released Preempted resources are added to the list of resources for which the process is waiting Process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting Circular Wait: impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration

Avoidance Requires that the system has some additional a priori information available Simplest and most useful model requires that each process declare the maximum number of resources of each type that it may need The deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that there can never be a circular-wait condition Resource-allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes