Deadlocks pp. 309. System Model 1.Request 2.Use 3.Release Necessary Conditions 1.Mutual exclusion (non-sharable) 2.Hold and wait (holding at least one.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 7: Deadlocks.
Deadlocks CS 3100 Deadlocks1. The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held by another.
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.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Deadlocks Gordon College Stephen Brinton. Deadlock Overview The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
What we will cover…  The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Objectives Understand the Deadlock.
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.
System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention, Avoidance, and Detection Recovering from Deadlock Combined Approach.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Chapter 7 Deadlocks. 7.2 Modified By Dr. Khaled Wassif Operating System Concepts – 7 th Edition Silberschatz, Galvin and Gagne ©2005 Chapter 7: 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.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-6 Deadlocks Department of Computer Science and Software Engineering.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization.
CHAPTER 8: DEADLOCKS System Model Deadlock Characterization
 The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock Avoidance  Deadlock.
Operating Systems (CS 340 D) Dr. Abeer Mahmoud Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Dr. Kalpakis CMSC 421, Operating Systems Deadlocks.
13/03/07Week 21 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
Chapter 7 Deadlocks Page 2 Chapter 7: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Deadlocks System Model RAG Deadlock Characterization
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks System Model Deadlock Characterization Methods.
Styresystemer og Multiprogrammering Block 3, 2005 Deadlocks Robert Glück.
Mi-Jung Choi Dept. of Computer and Science Silberschatz, Galvin and Gagne ©2006 Operating System Principles Chapter 7: Deadlocks.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 7 Operating Systems.
Chapter 8 Deadlocks. Objective System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection.
Chapter 7: Deadlocks. 7.2CSCI 380 – Operating Systems Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
CS307 Operating Systems Deadlocks Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
CSE Operating System Principles Deadlocks. CSE – Operating System Principles2 Overview System Model Deadlock Characterization Methods for.
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);
Chapter 7: Deadlocks. The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Chapter 7: Deadlocks.
Operating System Concepts
G.Anuradha Ref:- Galvin
Operating Systems (CS 340 D)
Chapter 7: Deadlocks.
Operating System: DEADLOCKS
Chapter 7 Deadlocks.
Process Deadlocks.
Chapter 7: Deadlocks System Model Deadlock Characterization
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
Outline Deadlocks, dead lock prevention, avoidance.
Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
Presentation transcript:

Deadlocks pp. 309

System Model 1.Request 2.Use 3.Release Necessary Conditions 1.Mutual exclusion (non-sharable) 2.Hold and wait (holding at least one resource, and wait) 3.No preemption (resources cannot be preempted) 4.Circular wait A process may utilize a resource in only the following sequence: necessary condition necessary condition event A event A necessary cond necessary cond event A ( )

Resource-Allocation Graph allocated wait

Resource-Allocation Graph Necessary but not sufficient!

Methods for Handling Deadlocks 1.Deadlock prevention Prevent at least one of the necessary conditions. 2.Deadlock avoidance Information in advance (wait/no wait requests). 3.Deadlock detection and recovery Deadlocks arise, detected, and recovered. 4.Do nothing Performance deterioration, stop functioning, and need to be manually restarted. necessary condition

Deadlock Prevention 1.Mutual exclusion Intrinsically non-sharable. 2.Hold and wait Request resources only when having none. 3.No preemption If a request fails, all resources are preempted. 4.Circular wait Request resources in increasing order. Read-only file (sharable) Memory (non-sharable) Whenever a process requests a resource, it does not hold any other resources. 2.1 Request all resources at the beginning (low utilization) 2.2 Release all resources before making a request (cannot always release) Example copy file from DVD to disk, sort, and print. A process that needs several popular resources may have to wait indefinitely (starvation). Often applied to resources whose state can be easily saved and restored later. CPU registers and memory.

F(tape drive) = 1 F(disk drive) = 5 F(printer) = 12 Each process can request resources only in an increasing order. 1. Process can request R j that F(R j ) > F(R i ) 2. If requesting R j, process must have released any R i that F(R i ) F(R j ). It must also be noted that if several instances of the same resource type are needed, a single request for all of them must be issued. If these two protocols are used, then the circular-wait condition cannot hold (proof by contradiction).

pp. 294 void transaction(Account from, Account to, double amount) { Semaphore lock1, lock2; lock1 = getLock(from); lock2 = getLock(to); wait(lock1); wait(lock2); withdraw(from, amount); deposit(to, amount); signal(lock1); signal(lock2); } Transaction(AccX, AccY, 25); Transaction(AccY, AccX, 50); AccX AccY It is also important to note that imposing a lock ordering does not guarantee deadlock prevention if locks can be acquired dynamically. Keep in mind that developing an ordering, or hierarchy, does not in itself prevent deadlock. It is up to application developers to write programs that follow the ordering. How to correct the program to solve deadlock?

Deadlock Avoidance

pp. 295

Total 12 tape drives. Safe sequence: Suppose that P 2 requests 1 more tape drive and is allocated. System is no longer in safe state. Deadlock may occur, for instance, P 1 is allocated and returns all tape drives (4 tapes are available). P 0 requests 5 and P 2 requests 6 tape drives. Deadlock! 4 tapes P0P0 P2P2 56 3

Resource-Allocation-Graph Algorithm pp. 297 Cycle-detection algorithm O(n 2 ) where n is number of processes. Go ahead Avoid it resource multiple instance !!!

Bankers Algorithm nnumber of processes mnumber of resource types Availablevector of length m (number of available instances) Maxn x m matrix (maximum demand) Allocationn x m matrix (number of allocated instances) Needn x m matrix (remaining resource need)

Safety? Algorithm 1.Work = Available// vector of length m Finish = (false, false, …, false)// vector of length n 2.Find an index i such that both a. Finish[i] = false b. Need i Work 3.Work = Work + Allocation i Finish[i] = true; Goto step 2 4.If Finish[i] == true for all i, then the system is in safe state. Time complexity = O(mn 2 ) cycle detection algorithm Main idea: safe sequence true process, false

Resource-Request Algorithm pp. 299 P 1 requests (1, 0, 2) and granted. Safe ( safe seq > 1) Safe, then granted P 4 requests (3, 3, 0)not enough available resources P 0 requests (0, 2, 0)unsafe Main idea: request safety algo safe

Deadlock Detection Single instance Resource-allocation graph called wait-for graph. Several instance Deadlock-detection algorithm (similar to Safety algo). Cycle = Deadlock

Deadlock-Detection Algorithm 1.Work = Available// vector of length m Finish = (true, false, … true)// vector of length n false if Allocation i 0 2.Find an index i such that both a. Finish[i] = false b. Request i Work 3.Work = Work + Allocation i Finish[i] = true; Goto step 2 4.If Finish[i] == false for some i, 0 i < n, then P i is deadlocked. Time complexity = O(mn 2 ) Main idea: best case process request process deadlock

pp. 303 No deadlock Deadlock! max need current request

Detection-Algorithm Usage 1.How often is a deadlock likely to occur? 2.How many processes will be effected by deadlock when it happens? Recovery from Deadlock 1.Process Termination Abort all deadlocked processes. Abort one process at a time until the deadlock cycle is eliminated. 2.Resource Preemption Selecting a victim. Rollback (due to resource preempted, total rollback = restart). Starvation (re-preempt from the same process over and over).