Concurrency: Deadlock and Starvation. Chapter 6

Similar documents
Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Operating Systems: William Stallings. Starvation. Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall

Concurrency: Deadlock and Starvation

Chapter 6 Concurrency: Deadlock and Starvation

ECE519 Advanced Operating Systems

Concurrency: Deadlock and Starvation. Chapter 6

Chapter 6 Concurrency: Deadlock and Starvation

Deadlock and Starvation

Deadlock and Starvation

CSE 306/506 Operating Systems Deadlock. YoungMin Kwon

Chapters 5 and 6 Concurrency

JOINT PROGRESS WITH DEADLOCK RESOURCE CATEGORIES AND DEADLOCK

DEADLOCK CS 409, FALL 2013 DEADLOCK AND STARVATION/1

Concurrency: Principles of Deadlock. Processes and resources. Concurrency and deadlocks. Operating Systems Fall Processes need resources to run

CSCC 69H3 2/1/13. Today: Deadlock. Remember example from last week? Example of Deadlock. Example: dining philosophers: Not just an OS Problem!

OPERATING SYSTEMS. Deadlocks

CSCE Operating Systems Deadlock. Qiang Zeng, Ph.D. Fall 2018

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

System Model. Types of resources Reusable Resources Consumable Resources

Last Class: Monitors. Real-world Examples

Operating Systems. Operating Systems Sina Meraji U of T

Deadlock 1 Chapter 6

The Deadlock Problem (1)

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

UNIT:2. Process Management

Deadlock 1 Chapter 6

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

Process Management And Synchronization

! What is a deadlock? ! What causes a deadlock? ! How do you deal with (potential) deadlocks? Maria Hybinette, UGA

6. Concurrency: Deadlock

Operating Systems Antonio Vivace revision 4 Licensed under GPLv3

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.

Deadlocks. Deadlock in Resource Sharing Environment. CIT 595 Spring Recap Example. Representing Deadlock

Deadlocks. Copyright : University of Illinois CS 241 Staff 1

Chapter 3. Deadlocks

Deadlock. Disclaimer: some slides are adopted from Dr. Kulkarni s and book authors slides with permission 1

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Deadlocks. Thomas Plagemann. With slides from C. Griwodz, K. Li, A. Tanenbaum and M. van Steen

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

Last Class: Synchronization Problems. Need to hold multiple resources to perform task. CS377: Operating Systems. Real-world Examples

Chapter 7: Deadlocks

Concurrency. Chapter 5

The deadlock problem

Deadlock and Monitors. CS439: Principles of Computer Systems September 24, 2018

Last Class: Synchronization Problems!

More on Synchronization and Deadlock

The Deadlock Lecture

!! What is a deadlock? !! What causes a deadlock? !! How do you deal with (potential) deadlocks? Maria Hybinette, UGA

Resource management. Real-Time Systems. Resource management. Resource management

Dr. Rafiq Zakaria Campus. Maulana Azad College of Arts, Science & Commerce, Aurangabad. Department of Computer Science. Academic Year

ECS 150 (Operating Systems) Goal To examine what causes deadlock, and what to do about it. Spring Quarter

The Slide does not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams.

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

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

DUH! Deadlocks. Concurrency Issues. The TENEX Case. If a process requests all systems buffers, operator console tries to print an error message

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017

Dealing with Issues for Interprocess Communication

Chapter 7: Deadlocks

DEADLOCKS M O D E R N O P E R A T I N G S Y S T E M S C H A P T E R 6 S P R I N G

Concurrency Issues. Past lectures: What about coordinated access across multiple objects? Today s lecture:

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Deadlock and Starvation

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

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

CS450/550 Operating Systems

OPERATING SYSTEM : RBMCQ0402. Third RavishBegusarai.

Shared and Preemptable Resources. A few resources may be sharable. Anyone can write the system log.

Operating systems. Lecture 5. Deadlock: System Model. Deadlock: System Model. Process synchronization Deadlocks. Deadlock: System Model

Module 1. Introduction:

Chapter 6: Process Synchronization

Chapter 7: Deadlocks 1

Chapter 3: Deadlocks

Lecture 3: Synchronization & Deadlocks

CMSC 412. Announcements

Deadlock Risk Management

Chapter 3. Deadlocks

Chapter 7: Deadlocks

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

Deadlock. Pritee Parwekar

Deadlocks. Today. Next Time. Resources & deadlocks Dealing with deadlocks Other issues. I/O and file systems

Resources. Lecture 4. Deadlocks. Resources (2) Resources (1) Four Conditions for Deadlock. Introduction to Deadlocks

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

Lecture Topics. Announcements. Today: Concurrency (Stallings, chapter , 5.7) Next: Exam #1. Self-Study Exercise #5. Project #3 (due 9/28)

Chapter 7: Deadlocks CS370 Operating Systems

Deadlocks. Mehdi Kargahi School of ECE University of Tehran Spring 2008

Concurrency Control Algorithms

Operating Systems. Lecture3.2 - Deadlock Management. Golestan University. Hossein Momeni

The Deadlock Problem

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

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

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; }

Chapter 2 Processes and Threads. Interprocess Communication Race Conditions

CS 153 Design of Operating Systems Winter 2016

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

Deadlocks. Today. Next Time. ! Resources & deadlocks! Dealing with deadlocks! Other issues. ! Memory management

VI. Deadlocks. What is a Deadlock? Intended Schedule. Deadlock Problem (1) ???

VI. Deadlocks Operating Systems Prof. Dr. Marc H. Scholl DBIS U KN Summer Term

PROCESS SYNCHRONIZATION

Deadlock and Monitors. CS439: Principles of Computer Systems February 7, 2018

Transcription:

Concurrency: Deadlock and Starvation Chapter 6

Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other Involve conflicting needs for resources by two or more processes

Example of Deadlock Progress of Q A Required Release A Release B 1 2 P and Q want A B Required Get A Get B 3 deadlock inevitable 4 P and Q want B 5 6 Get A Get B Release A Release B Progress of P A Required B Required

Example of No Deadlock Progress of Q A Required Release A Release B 1 2 3 P and Q want A 4 B Required Get A Get B P and Q want B 5 6 Get A Release A Get B Release B Progress of P A Required B Required

Reusable, Nonsharable Resources Used by one process at a time and not depleted by that use Processes obtain resources that they later release for reuse by other processes Processor time, I/O channels, main and secondary memory, files, databases, and semaphores Deadlock occurs if each process holds one resource and requests the other

Example of Deadlock Space is available for allocation of 200K bytes, and the following sequence of events occur... P1 Request 80K bytes;... Request 60K bytes;... P2 Request 70K bytes;... Request 80K bytes; Deadlock occurs if both processes progress to their second request

Consumable Resources Created (produced) and destroyed (consumed) by a process Interrupts, signals, messages, and information in I/O buffers Deadlock may occur if a Receive message is blocking May take a rare combination of events to cause deadlock

Example of Deadlock Deadlock occurs if receive is blocking... Receive(P2);... Send(P2); P1... Receive(P1);... Send(P1); P2

Conditions for Deadlock Mutual exclusion only one process may use a resource at a time Hold-and-wait a process is allowed to hold allocated resources while awaiting assignment of others No preemption no resource can be forcibly removed from a process holding it

Conditions for Deadlock Circular wait A closed chain of processes exists, such that each process holds at least one resource needed by the next process in the chain Necessary for deadlock to happen Sufficient under certain circumstances Other conditions are necessary but not sufficient for deadlock

Circular Wait Resource A Process P1 Process P2 Resource B

Deadlock Prevention Disallowing Mutual Exclusion cannot be achieved, due to the nature of nonsharable resources Disallowing Hold-and-Wait Require that a process request all its required resources at once Block the process until all requests can be granted simultaneously Problem: o process can be held up for a long time waiting for all its requests o starvation is possible

Deadlock Prevention Disallowing No Preemption If a process is denied a further request, the process must release the original resources If a process cannot obtain a resource, the process may have to release the resources it already holds. Process must have capability to restore these resources to current state. Practical only only when the state can be easily saved and restored later, such as the CPU or main memory.

Deadlock Prevention Disallowing Circular Wait define a linear ordering for resources once a resource is obtained, only those resources that have id number higher can be obtained (if a process requests a resource with lower id number than what it has obtained so far, that request is denied) Problem: may deny resources for no reason other than the wrong id number. Low resource utilization.

Deadlock Avoidance Do not start a process if its demands might lead to deadlock Do not grant an incremental resource request to a process if this allocation might lead to deadlock Not necessary to preempt and rollback processes

Deadlock Avoidance Maximum resource requirement must be stated in advance Processes under consideration must be independent; no synchronization requirements There must be a fixed number of resources to allocate No process may exit while holding resources

Deadlock Avoidance: The Banker s Algorithm Assume: M resources R1,, RM o system has several identical copies of each resource: Q1,, QM (maximums/resource) o a process can ask for several copies of each resource type; doesn t care which specific copies are given as long as they are of the requested type State: a particular allocation of resources to processes: P1 P2 P3 P4 resources R1 3 0 1 2 Q1=9 R2 2 4 0 1 Q2=7 R3 Q3=4 0 0 1 2 processes

Deadlock Avoidance: Banker s Algorithm Safe state: state where we can order the remaining processes so they can run to completion without a deadlock. A safe state test: // Let L be the list of unfinished processes while L is non-empty do if can find process P in L whose outstanding requests can be satisfied using available resources then { delete P from L add all resources held by P to the pool of available resources } else return(unsafe) return (safe) This is only a sufficient - not a necessary, condition for safety!

Deadlock Avoidance: Banker s Algorithm Request granting algorithm req(p,qty,rsrc): if Qty+allocated(P,Rsrc) > limit(rsrc) then abort P; tentatively allocate request; if safe(resulting state) then grant request; else suspend P on Rsrc;

Deadlock Detection Operating system checks for deadlock When: Check at resource request time o early detection of deadlock o frequent checks consume processor time Check periodically o deadlocks stay undetected between checks

Strategies once Deadlock Detected Abort all deadlocked processes Back up each deadlocked process to some previously defined checkpoint, and restart all processes original deadlock may occur once again Successively abort deadlocked processes until deadlock no longer exists Successively preempt resources until deadlock no longer exists (if resource preemption is feasible and cost-effective)

Selection Criteria Deadlocked Processes Least amount of processor time consumed so far (so the least amount of work will be wasted) Least number of lines of output produced so far (so cheaper to preempt file resources) Most estimated time remaining (presumably, this process is most deadlock-prone) Least total resources allocated so far Lowest priority

Deadlock Detection Algorithms Single instance of each resource draw a resource request graph as follows: o arc Proc --> Res exists if Proc requested Res o arc Proc <-- Res exists if Proc holds Res The system has a deadlock iff the resource request graph has a cycle o Why? o Multiple resource instances: is the cycle condition necessary for the existence of a deadlock? Is it sufficient?

Deadlock Detection Algorithms Multiple resource instances similar to the safety test: // Let L be the list of all unfinished processes while nonempty(l) do{ if found a process P in L all of whose requests can be satisfied with available resources do { delete P from L; add all resources held by P to the pool of available resources; } else return(deadlock); } return(nodedlock); The algorithm ensures that if none of the processes issues additional resource requests, then there is no deadlock.

Dining Philosophers Problem Illustrates: -deadlocks -starvation

Dining Philosophers Solutions // 5 philosophers // & forks semaphore fork[4]; With starvation & deadlock: // at most 4 out of 5 // philosophers eat simultaneously semaphore room = 4; No starvation or deadlock: repeat <think> wait(fork[i]); wait(fork[(i+1)mod 5]); <eat> signal(fork[i]); signal(fork[(i+1)mod 5]); forever Give a scenario for deadlock. Give a scenario for starvation. repeat <think> wait(room); wait(fork[i]); wait(fork[(i+1)mod 5]); <eat> signal(fork[(i+1)mod 5]); signal(fork[i]); signal(room); forever

Interprocess Concurrency Mechanisms Pipes buffer allowing two processes to communicate queue written by one process and read by another operating system enforces mutual exclusion for writing and reading the pipe write requests are immediately executed if there is room in the pipe, otherwise the process is blocked read request is blocked if attempts to read more bytes than currently available in the pipe

Inter-process Concurrency Mechanisms Messages block of text with accompanying type receiver can either retrieve messages in FIFO order or by type process suspends when trying to send a message to a queue that is full process suspends when reading from an empty queue process trying to read a certain type of messages fails, not suspended

Inter-process Concurrency Mechanisms Shared memory common block of virtual memory shared by multiple processes fast form of interprocess communication mutual exclusion must be provided by the processes, not the operating system

Inter-process Concurrency Mechanisms Semaphores wait and signal and much more operating system handles all these requests Signals (UNIX-derived OS only) software mechanism that informs a process of the occurrence of asynchronous events e.g. interrupt process, quit process, kill process, floating point exception,...

Solaris Thread Synchronization Primitives Mutual exclusion lock prevents more than one thread from proceeding when the lock is acquired Semaphores used for incrementing and decrementing Unlike the general synchronization primitives (which operate on resources shared by all threads of a process), these synchronization resources aren t shared by threads in the same process!

Solaris Thread Synchronization Primitives Multiple readers, single writer locks multiple threads have simultaneous read-only access only one thread has access for writing Condition variables used to wait until a particular condition is true

Windows NT Concurrency Mechanisms Synchronization Objects process thread file console input file change notification mutex semaphore (counting) event waitable timer Each synchronization object can be in either signaled or un-signaled state Un-signaled state: thread can be suspended on synchronization objects that are un-signaled Signaled state: when object is in signaled state, all threads waiting on this object wake up