Lecture 26 Syed Mansoor Sarwar

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks Adapted by Donghui Zhang from the original version by Silberschatz et al.
Advertisements

ICS Principles of Operating Systems Lectures 8 and 9 - Deadlocks Prof. Dmitri V. Kalashnikov dvk ics.uci.edu Slides © Prof. Nalini Venkatasubramanian.
Operating Systems Lecture Notes Deadlocks Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
Deadlock Prevention, Avoidance, and Detection.  The Deadlock problem The Deadlock problem  Conditions for deadlocks Conditions for deadlocks  Graph-theoretic.
DEADLOCK. Contents  Principles of deadlock  Deadlock prevention  Deadlock detection.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 27 CPU Simulator III.
02/27/2004CSCI 315 Operating Systems Design1 Process Synchronization Deadlock Notice: The slides for this lecture have been largely based on those accompanying.
02/19/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Chapter 7: Deadlocks. 7.2 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks.
Modified from Silberschatz, Galvin and Gagne Lecture 13 Chapter 7: Deadlocks.
02/18/2008CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Bridge Crossing Example Traffic only in one direction. Each section.
Monitors High-level synchronization construct that allows the safe sharing of an abstract data type among concurrent processes. monitor monitor-name {
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlocks.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
Cosc 4740 Chapter 6, Part 4 Deadlocks. The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held.
Chapter 8: Deadlocks Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection Recovery from Deadlock.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
 The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock Avoidance  Deadlock.
CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 7 Operating Systems.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
Deadlocks - System Model - Deadlock characterization - Methods for handling deadlocks - Deadlock prevention,avoidance - Deadlock detection and recovery.
Deadlock. Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock.
Deadlocks Introduction to Operating Systems: Module 7.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Deadlocks.
Operating Systems Unit 4: – Dining Philosophers – Deadlock – Indefinite postponement Operating Systems.
7.1 CSE Department MAITSandeep Tayal 7: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
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);
CSS430 Deadlocks Textbook Ch7
Thursday, February 23, 2012 Chapter 6 homework questions?
Chapter 7: Deadlocks.
Synchronization Deadlocks and prevention
Auburn University COMP 3500 Introduction to Operating Systems Resource Allocation Graphs Handling Deadlocks Dr. Xiao.
Chapter 7: Deadlocks.
Synchronization Deadlocks and prevention
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks Source & Copyright: Operating System Concepts, Silberschatz, Galvin and Gagne.
Operating Systems (CS 340 D)
Chapter 7: Deadlocks.
Operating System: DEADLOCKS
Chapter 7 Deadlocks.
Chapter 7: Deadlocks.
Lecture 25 Syed Mansoor Sarwar
COP 4600 Operating Systems Fall 2010
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 1/11/2019 B.Ramamurthy.
Lecture 6: Deadlocks, Deadlock Risk Management
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
CSc 552 Advanced Unix Process deadlock deadlock prevention
Deadlock B.Ramamurthy CSE421 2/23/2019 B.Ramamurthy.
Deadlocks Session - 13.
Lecture 27 Syed Mansoor Sarwar
Chapter 7: Deadlocks.
More IPC B.Ramamurthy 4/15/2019.
Deadlock B.Ramamurthy CSE421 4/23/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 5/1/2019 B.Ramamurthy.
CSCI 315 Operating Systems Design
CENG334 Introduction to Operating Systems
Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
Chapter 8: Deadlocks Deadlock Characterization
OPERATING SYSTEM CONCEPTS
Deadlock B.Ramamurthy CSE421 8/28/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 9/3/2019 B.Ramamurthy.
Presentation transcript:

Lecture 26 Syed Mansoor Sarwar Operating Systems Lecture 26 Syed Mansoor Sarwar

© Copyright Virtual University of Pakistan Agenda for Today Review of previous lecture Monitors—Dining Philosophers The deadlock problem Deadlock characterization Deadlock handling Deadlock prevention Recap of lecture 19 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Review of Lecture 25 Dining philosophers problem High-level language constructs Critical region Monitor 19 April 2019 © Copyright Virtual University of Pakistan

Dining Philosophers Example monitor dp { enum {thinking, hungry, eating} state[5]; condition self[5]; void pickup(int i) // Following slides void putdown(int i) // Following slides void test(int i) // Following slides void init() { for (int i = 0; i < 5; i++) state[i] = thinking; } 19 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Dining Philosophers void pickup(int i) { state[i] = hungry; test(i); if (state[i] != eating) self[i].wait(); } 19 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Dining Philosophers void putdown(int i) { state[i] = thinking; // test left and right // neighbors test((i+4) % 5); test((i+1) % 5); } 19 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Dining Philosophers void test(int i) { if ((state[(i+4)%5]!= eating) && (state[i] == hungry) && (state[(i+1)%5]!= eating)) { state[i] = eating; self[i].signal(); } 19 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan 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. 19 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan The Deadlock Problem Example System has 2 tape drives. P1 and P2 each hold one tape drive and each needs another one. 19 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan The Deadlock Problem Example: semaphores A and B, initialized to 1 P0 P1 wait (A); wait(B); wait (B); wait(A); 19 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan The Deadlock Problem signal(A); P0 P1 signal(B); 19 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan The Deadlock Problem The Dining Philosophers problem … all philosophers become hungry at the same time, pick up the chopsticks on their right and wait for getting the chopsticks on their left. 19 April 2019 © Copyright Virtual University of Pakistan

Bridge Crossing Example Traffic only in one direction. Each section of a bridge can be viewed as a resource. 19 April 2019 © Copyright Virtual University of Pakistan

Bridge Crossing Example 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. 19 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan System Model Resource types R1, R2, . . ., Rm (CPU cycles, memory space, I/O devices) Each resource type Ri has Wi instances. Each process utilizes a resource as follows: request → use → release 19 April 2019 © Copyright Virtual University of Pakistan

Deadlock Characterization Deadlock can arise if four conditions hold simultaneously. Mutual exclusion: only one process at a time can use a resource. 19 April 2019 © Copyright Virtual University of Pakistan

Deadlock Characterization Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes. 19 April 2019 © Copyright Virtual University of Pakistan

Deadlock Characterization No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task. 19 April 2019 © Copyright Virtual University of Pakistan

Deadlock Characterization Circular wait: There exists a set {P0, P1, …, P0} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and P0 is waiting for a resource that is held by P0. P0 → P1 → P2 → … → Pn → P0 19 April 2019 © Copyright Virtual University of Pakistan

Resource Allocation Graph A set of vertices V and a set of edges E. V is partitioned into two types: P = {P1, P2, …, Pn} R = {R1, R2, …, Rm} E = {Request Edges, Assignment Edges} Request Edge: P1  Rj Assignment Edge: Rj  Pi 19 April 2019 © Copyright Virtual University of Pakistan

Resource Allocation Graph Process Resource Type with 4 instances Pi requests instance of Rj Pi is holding an instance of Rj Pi Pi 19 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example Graph 19 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Graph with a Deadlock 19 April 2019 © Copyright Virtual University of Pakistan

Graph with a Cycle but No Deadlock 19 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Basic Facts If graph contains no cycles  no deadlock. If graph contains a cycle  if only one instance per resource type, then deadlock. if several instances per resource type, possibility of deadlock. 19 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Recap of Lecture Monitor-based implementation of the dining philosophers problem The deadlock problem The system model Deadlock characterization The resource allocation graph 19 April 2019 © Copyright Virtual University of Pakistan

Lecture 26 Syed Mansoor Sarwar Operating Systems Lecture 26 Syed Mansoor Sarwar