Operating Systems Unit 4: – Dining Philosophers – Deadlock – Indefinite postponement Operating Systems.

Slides:



Advertisements
Similar presentations
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Advertisements

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.
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.
Chapter 7: Deadlocks.
02/27/2004CSCI 315 Operating Systems Design1 Process Synchronization Deadlock Notice: The slides for this lecture have been largely based on those accompanying.
Deadlock CS Introduction to Operating Systems.
7.5 Deadlock Avoidance The algorithm is simply to ensure that the system will always remain in safe state. Therefore, if a process requests a resource.
Ceng Operating Systems Chapter 2.4 : Deadlocks Process concept  Process scheduling  Interprocess communication  Deadlocks Threads.
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 7 – Deadlock and Indefinite Postponement Outline 7.1 Introduction 7.2Examples of Deadlock.
7.4 Resource Concepts Preemptible resources (e.g. processors and main memory) –Can be removed from a process without loss of work Nonpreemptible resources.
Chapter 3 Deadlocks TOPICS Resource Deadlocks The ostrich algorithm
02/19/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
Chapter 7: Deadlocks. 7.2 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks.
1 Chapter 7: Deadlock. 2 The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Deadlock CSCI 444/544 Operating Systems Fall 2008.
Concurrency: Deadlock & Starvation
CS 450 OPERATING SYSTEMS DEADLOCKS Manju Muralidharan Priya.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
CPSC 4650 Operating Systems Chapter 6 Deadlock and Starvation
Chapter 7 – Deadlock and Indefinite Postponement
1 Concurrency: Deadlock and Starvation Chapter 6.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
02/25/2004CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Chapter 6 Concurrency: Deadlock and Starvation
Silberschatz, Galvin and Gagne  Operating System Concepts Deadlock and Starvation Deadlock – two or more processes are waiting indefinitely for.
Concurrency: Deadlock and Starvation Chapter 6. Goal and approach Deadlock and starvation Underlying principles Solutions? –Prevention –Detection –Avoidance.
1 Concurrency: Deadlock and Starvation Chapter 6.
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.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Operating Systems Part III: Process Management (Deadlocks)
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
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.
Deadlocks Silberschatz Ch. 7 and Priority Inversion Problems.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
Chapter 7 Deadlocks. 7.1 Introduction Deadlock Common approaches to deal with deadlock – Prevention – Avoidance – Detection and recovery.
Deadlocks System Model RAG Deadlock Characterization
Chapter 7 Deadlocks Chapter 7: Deadlocks 7.1 System Model 7.2 Deadlock Characterization 7.3 Methods for Handling Deadlocks 7.4 Deadlock Prevention 7.5.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings.
Deadlock Conditions for Deadlock Deadlock Prevention Deadlock Detection Deadlock Recovery Dining Philosophers Semaphores.
Deadlocks Mark Stanovich Operating Systems COP 4610.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 7 Operating Systems.
Operating Systems Unit VI Deadlocks and Protection Department of Computer Science Engineering and Information Technology.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
Deadlocks Introduction to Operating Systems: Module 7.
Deadlocks Copyright ©: University of Illinois CS 241 Staff1.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.
Deadlock CS Introduction to Operating Systems.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Deadlock.
Informationsteknologi Monday, October 1, 2007Computer Systems/Operating Systems - Class 111 Today’s class Deadlock.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
NETW 3005 Monitors and Deadlocks. Reading For this lecture, you should have read Chapter 7. NETW3005 (Operating Systems) Lecture 06 - Deadlocks2.
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);
Process Management Deadlocks.
Synchronization Deadlocks and prevention
Concurrency: Deadlock and Starvation
Chapter 7 – Deadlock and Indefinite Postponement
Chapter 7 Deadlock.
Lecture 25 Syed Mansoor Sarwar
Conditions for Deadlock
Andy Wang Operating Systems COP 4610 / CGS 5765
Lecture 26 Syed Mansoor Sarwar
Chapter 8: Deadlocks Deadlock Characterization
Presentation transcript:

Operating Systems Unit 4: – Dining Philosophers – Deadlock – Indefinite postponement Operating Systems

COP Operating Systems2 Dining Philosophers

COP Operating Systems3 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; }

COP Operating Systems4 Dining Philosophers void pickup(int i) { state[i] = hungry; test(i); if (state[i] != eating) self[i].wait(); }

COP Operating Systems5 Dining Philosophers void putdown(int i) { state[i] = thinking; // test left and right neighbors test((i+4) % 5); test((i+1) % 5); }

COP Operating Systems6 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(); }

COP Operating Systems7 Java Monitors enables thread mutual exclusion and synchronization Signal-and-continue monitors –Allow a thread to signal that the monitor will soon become available –Maintain a lock on monitor until thread exits monitor method keyword synchronized

COP Operating Systems8 Java Monitors wait method –releases lock on monitor, thread is placed in wait set –condition variable is “this” object –when thread reenters monitor, reason for waiting may not be met notify and notifyAll –signal waiting thread(s)

COP Operating Systems9 Dining Philosopher with Semaphore ? semaphore chopstick[5]; // Initially set to 1 Philosopher i: do { wait(chopstick[i]) wait(chopstick[(i+1) % 5]) … eat … signal(chopstick[i]); signal(chopstick[(i+1) % 5]); … think … } while (1); Deadlock ?

COP Operating Systems10 Deadlock

COP Operating Systems11 Simple Resource Deadlock

COP Operating Systems12 Related: Indefinite postponement Also called indefinite blocking or starvation –Occurs due to biases in a system’s resource scheduling policies Aging –Technique that prevents indefinite postponement by increasing process’s priority as it waits for resource

COP Operating Systems13 Concepts: sharing & preemption some resources may be shared –files, devices, code, … preemptible resources –e.g. processors and main memory –can be removed from a process without loss of work non-preemptible resources –e.g. tape drives and optical scanners –cannot be removed from the process without loss of work

COP Operating Systems14 Conditions for Deadlock Mutual exclusion –resource accessed by only one process at a time Hold-and-wait-for –process holds resource(s) while waiting for other resource(s) No-preemption –system cannot remove resource from the process until the process has finished using the resource Circular-wait –processes are in a “circular chain” where each process is waiting for resource(s) of next process in chain

COP Operating Systems15 Dealing with Deadlock Deadlock prevention Deadlock avoidance Deadlock detection Deadlock recovery

COP Operating Systems16 Deadlock Prevention Condition a system to remove any possibility of deadlocks occurring –avoid the four deadlock conditions –mutual exclusion cannot be avoided

COP Operating Systems17 Denying the “Wait-For” Condition process must request all resources at once inefficient resource allocation

COP Operating Systems18 Denying the “No-Preemption” Condition preempt resource from process loss of work substantial overhead for process restart

COP Operating Systems19 Denying the “Circular-Wait” Condition Use a linear ordering of resources –each resource gets unique number –process requests resources in ascending order Drawbacks –Requires the programmer to determine the ordering or resources for each system

COP Operating Systems20 Dijkstra’s Banker’s Algorithm deadlock avoidance –less stringent than deadlock prevention –control resource allocation –yields better resource utilization idea: –grant resource to process in return for promise to release it in “finite time” –differentiate between safe and unsafe states –allocate resources to processes only if it results in safe state

COP Operating Systems21 Banker’s Algorithm: assumptions fixed number of identical resources fixed number of processes max(P i ) : –maximum number of resources for Process P i loan(P i ) : –current number of resources held by Process P i claim(P i ) : –max(P i ) - loan(P i )

COP Operating Systems22 Example: Safe State guarantees that all current processes can complete their work within a finite time P 2 may proceed to completion

COP Operating Systems23 Example: Unsafe State no process can guarantee to complete

COP Operating Systems24 Safe-State-to-Unsafe-State Transition P 3 requests an additional resource

COP Operating Systems25 Banker’s Algorithm example safe or unsafe ? unsafe

COP Operating Systems26 Weaknesses in the Banker’s Algorithm Requires fixed number of resources Requires fixed population of processes only requires granting all requests within “finite time” only requires that clients return resources within “finite time” Requires processes to state maximum needs in advance

COP Operating Systems27 Deadlock Detection problem: –has deadlock occurred ? how to determine if deadlock has occurred –check for circular wait can incur significant runtime overhead

COP Operating Systems28 Tool: Resource-Allocation Graph

COP Operating Systems29 Tool: Resource-Allocation Graph

COP Operating Systems30 Reduction of Resource-Allocation Graphs Rules –If a process’s resource requests may be granted, the graph may be reduced by that process –If a graph can be reduced by all its processes, there is no deadlock –If a graph cannot be reduced by all its processes, the irreducible processes constitute the set of deadlocked processes in the graph

COP Operating Systems31 Example: Graph Reduction 1/4

COP Operating Systems32 Example: Graph Reduction 2/4

COP Operating Systems33 Example: Graph Reduction 3/4

COP Operating Systems34 Example: Graph Reduction 4/4

COP Operating Systems35 Process termination –Abort all deadlocked processes –Abort one process at a time until the deadlock cycle is eliminated considerations: –suspend/resume feature –checkpoint/rollback Deadlock Recovery

COP Operating Systems36 In which order should we choose to abort? –Priority of the process –How long process has computed, and how much longer to completion –Resources the process has used –Resources process needs to complete –How many processes will need to be terminated –Is process interactive or batch? Deadlock Recovery

COP Operating Systems37 Current Deadlock Strategies Deadlock is viewed as limited annoyance in personal computer systems –Some systems implement basic prevention methods –Some others ignore the problem, because checking deadlocks would reduce systems’ performance Deadlock continues to be an important research area

COP Operating Systems38 Agenda for next week: Chapter 8 –Processor scheduling Read ahead !