OS Spring 2004 Concurrency: Principles of Deadlock Operating Systems Spring 2004.

Slides:



Advertisements
Similar presentations
1 Concurrency: Deadlock and Starvation Chapter 6.
Advertisements

1 Concurrency: Deadlock and Starvation Chapter 6.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
1 Concurrency: Deadlock and Starvation Chapter 6.
Deadlock Prevention, Avoidance, and Detection
ICS Principles of Operating Systems Lectures 8 and 9 - Deadlocks Prof. Dmitri V. Kalashnikov dvk ics.uci.edu Slides © Prof. Nalini Venkatasubramanian.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Lecture 6 :Deadlocks. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other Involves.
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.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
6. Deadlocks 6.1 Deadlocks with Reusable and Consumable Resources
Chapter 6 Concurrency: Deadlock and Starvation
Chapter 6 Concurrency: Deadlock and Starvation
Chapter 81 Deadlock is:  A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.  Example.
Chapter 3 Deadlocks TOPICS Resource Deadlocks The ostrich algorithm
Chapter 6 Concurrency: Deadlock and Starvation I
Avishai Wool lecture Introduction to Systems Programming Lecture 5 Deadlocks.
Chapter 6 Concurrency: Deadlock and Starvation
CSI 400/500 Operating Systems Spring 2009 Lecture #17 –Deadlocks Wednesday, April 15 th.
1 Wednesday, June 28, 2006 Command, n.: Statement presented by a human and accepted by a computer in such a manner as to make the human feel that he is.
Deadlocks. 2 System Model There are non-shared computer resources –Maybe more than one instance –Printers, Semaphores, Tape drives, CPU Processes need.
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
Concurrency: Deadlock & Starvation
CS 450 OPERATING SYSTEMS DEADLOCKS Manju Muralidharan Priya.
The ‘deadlock’ conditions Reviewing some key points concerning the potential for ‘deadlock’ in an operating system.
1 Lecture 8: Deadlocks Operating System Spring 2008.
1 M. Bozyigit ICS Operating Systems Deadlock. 2 Deadlock n Permanent blocking of a set of processes that either compete for system resources or communicate.
Witawas Srisa-an Chapter 6
CPSC 4650 Operating Systems Chapter 6 Deadlock and Starvation
OS Fall’02 Concurrency: Principles of Deadlock Operating Systems Fall 2002.
1 Concurrency: Deadlock and Starvation Chapter 6.
Chapter 6 Concurrency: Deadlock and Starvation
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.
Concurrency: Deadlock and Starvation
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
1 Announcements The fixing the bug part of Lab 4’s assignment 2 is now considered extra credit. Comments for the code should be on the parts you wrote.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
Operating System Chapter 6. Concurrency: Deadlock and Starvation Lynn Choi School of Electrical Engineering.
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
CIS Operating Systems Deadlock Professor Qiang Zeng Fall 2015.
Resource Management Reusable  Disk blocks  File descriptors  Semaphores Consumable  Messages  Packets.
Deadlock Operating Systems: Internals and Design Principles.
Chapter 7 Deadlocks. 7.1 Introduction Deadlock Common approaches to deal with deadlock – Prevention – Avoidance – Detection and recovery.
Chapter 6 Concurrency: Deadlock and Starvation
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings.
Chapter 8 Deadlocks. Objective System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.
Informationsteknologi Monday, October 1, 2007Computer Systems/Operating Systems - Class 111 Today’s class Deadlock.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Concurrency: Deadlock and Starvation
Operating systems Deadlocks.
ITEC 202 Operating Systems
Chapter 12: Concurrency, Deadlock and Starvation
Deadlock B.Ramamurthy CSE421 9/17/2018 B.Ramamurthy.
Advanced Operating System Fall 2009
Chapter 7 Deadlock.
Operating systems Deadlocks.
Banker`s Algorithm Developed by Dijkstra in 1965
DEADLOCK.
Operating System 6 CONCURRENCY: MUTUAL EXCLUSION AND SYNCHRONIZATION
Deadlock B.Ramamurthy CSE421 4/26/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CS421 5/4/2019 B.Ramamurthy.
CSE 542: Operating Systems
CSE 542: Operating Systems
Presentation transcript:

OS Spring 2004 Concurrency: Principles of Deadlock Operating Systems Spring 2004

OS Spring 2004 Processes and resources  Processes need resources to run CPU, memory, disk, etc … A process waiting for a resource cannot complete its execution until the resource becomes available  There is only a finite amount of resources E.g., 1 CPU, 1 GB memory, 2 disks

OS Spring 2004 Concurrency and deadlocks  In a multiprogramming system the total resource demand by all concurrently active processes exceeds by far the total amount of available resources  Processes compete for resources A process can grab the last instance of a resource A and wait for the resource B Another process may hold B and wait for A No one can proceed: Deadlock

OS Spring 2004 Deadlock  Permanent blocking of a set of processes that either compete for system resources or communicate with each other  Involves conflicting needs for resources by two or more processes  There is no satisfactory solution in the general case

OS Spring 2004 Deadlock in the everyday life

OS Spring 2004 Deadlock in the everyday life

OS Spring 2004 Deadlock when contending for the critical section

OS Spring 2004 Example of Deadlock Progress of Q Release A Release B Get A Get B Get AGet BRelease ARelease B Progress of P A Required B Required A Required B Required deadlock inevitable P and Q want A P and Q want B

OS Spring 2004 Example of No Deadlock Progress of Q Release A Release B Get A Get B Get ARelease AGet BRelease B Progress of P A Required B Required A Required B Required P and Q want A P and Q want B

OS Spring 2004 Resource categories  Reusable: Used by one process at a time and not depleted by that use  can be reused by other processes,may exist several instances Processors, memory, disks, tapes, etc.  Consumable: Created (produced) and destroyed (consumed) by a process  Interrupts, signals, messages, and information in I/O buffers

OS Spring 2004 Reusable resources and Deadlock  Deadlock might occur if each process holds one resource and requests the other  E.g., Space is available for allocation of 200K P1... Request 80K bytes; Request 60K bytes; P2... Request 70K bytes; Request 80K bytes;

OS Spring 2004 Consumable resources and Deadlock  Example: Deadlock occurs if receive is blocking P1... Receive(P2); Send(P2); P2... Receive(P1); Send(P1);

OS Spring 2004 Conditions for Deadlock  Policy conditions Mutual exclusion Hold-and-wait No preemption  Circular wait Resource B Resource A Process P1 Process P2 Requests Held by Requests Held By

OS Spring 2004 Conditions for Deadlock Mutual exclusion Hold-and-wait No preemption Circular wait DEADLOCK

OS Spring 2004 Circular Wait P1P2P3 R1 R2 R3

OS Spring 2004 No circular wait P1P2P3 R1 R2 R3

OS Spring 2004 Coping with Deadlocks  Deadlock prevention Deadlock possibility is excluded a priori by the system design  Deadlock avoidance Deadlocks are possible in principle but avoided  Deadlock detection Deadlocks can occur: detect and solve the problem

OS Spring 2004 Deadlock prevention  Design system so that it violates one of the four necessary conditions Prevent hold and wait:  request all the resources at the outset  wait until all the resources are available Prevent circular wait by defining linear ordering of the resource types  A process holding some resources can request only resource types with higher numbers

OS Spring 2004 Preventing circular wait P1P2P3 R1 R2 R3

OS Spring 2004 Deadlock prevention: Cons  Degraded performance Delayed execution Low parallelism  Hold and wait prevention is wasteful Hold resources more than they are needed When might this be reasonable?

OS Spring 2004 Deadlock avoidance  Allocate resources in a way that assures that the deadlock point is never reached  The allocation decision is made dynamically based on total amount of resources available currently available processes ’ resource claim processes ’ current resources allocation

OS Spring 2004 Banker ’ s algorithm ( Dijkstra 65 ’ )  Do not grant an incremental resource request to a process is this allocation might lead to deadlock  The system state: is the current allocation of resources to processes  Safe state: is a state in which there is at least one sequence in which all processes can be run to completion  Unsafe state = NOT safe state

OS Spring 2004 Determination of the safe state  We have 3 resources types with amount: R(1) = 9, R(2) = 3, R(3) = 6  Is the state S0 below safe? Claim Allocated Total P1 P2 P3 P4 R1 R2 R Available 0 1 1

OS Spring 2004 Determination of the safe state Claim Allocated Total P1 P2 P3 P4 R1 R2 R Available Claim Allocated Total P1 P2 P3 P4 R1 R2 R Available 7 2 3

OS Spring 2004 Determination of the safe state Claim Allocated Total P1 P2 P3 P4 R1 R2 R Available Claim Allocated Total P1 P2 P3 P4 R1 R2 R Available S0 is safe: P2->P1->P3->P4

OS Spring 2004 Banker ’ s algorithm  When a process request resources: Assume the request is granted Update the system state accordingly Determine whether the resulting state is safe If yes: grant the resources Otherwise, block the process until it is safe to grant the resources

OS Spring 2004 Banker ’ s algorithm Claim Allocated Total P1 P2 P3 P4 R1 R2 R Available P2 requests (1, 0, 1): Grant or not? P1 requests (1, 0, 1): Grant or not?

OS Spring 2004 Deadlock detection  Banker ’ s algorithm is Pessimistic: always assume that a process will not release the resources until it got ’ m all  decreased parallelism Involves complicated checks for each resource allocation request (O(n^2))  Optimistic approach: don ’ t do any checks When deadlock occurs - detect and recover Detection: look for circular waits

OS Spring 2004 Practice  Most operating systems employ an “ ostrich ” algorithm  Break hold-and-wait Cannot acquire a resource - fail back to the user:  e.g., too many processes, too many open files  Quotas  Programming discipline: acquire locks (semaphores) in a specific order

OS Spring 2004 Dining philosophers problem

OS Spring 2004 Dining philosophers problem  An abstract problem demonstrating some fundamental limitations of the deadlock- free synchronization  There is no symmetric solution  Solutions execute different code for odd/even give ’ m another fork allow at most 4 philosophers at the table Randomized (Lehmann-Rabin)

OS Spring 2004 Concurrency: summary  Critical section is an abstract problem for studying concurrency and synchronization software solutions hardware primitives higher level primitives: semaphores, monitors  Deadlocks are inherent to concurrency 4 conditions 3 ways to cope with