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

Similar documents
Chapter 8: Deadlocks. The Deadlock Problem

The Deadlock Problem. Chapter 8: Deadlocks. Bridge Crossing Example. System Model. Deadlock Characterization. Resource-Allocation Graph

Chapter 8: Deadlocks. Bridge Crossing Example. The Deadlock Problem

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.

Process Synchronisation (contd.) Deadlock. Operating Systems. Spring CS5212

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Deadlocks. Minsoo Ryu. Real-Time Computing and Communications Lab. Hanyang University.

Chapter 7: Deadlocks

Chapter 7: Deadlocks

The Deadlock Problem

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

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

Chapter 8: Deadlocks

Chapter 8: Deadlocks. The Deadlock Problem. System Model. Bridge Crossing Example. Resource-Allocation Graph. Deadlock Characterization

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

Chapter 7: Deadlocks. Chapter 7: Deadlocks. The Deadlock Problem. Chapter Objectives. System Model. Bridge Crossing Example

Module 7: Deadlocks. The Deadlock Problem. Bridge Crossing Example. System Model

The Deadlock Problem

Chapter 8: Deadlocks. The Deadlock Problem

CMSC 412. Announcements

Chapter 7: Deadlocks

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

Bridge Crossing Example

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

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.

CS307 Operating Systems Deadlocks

Lecture 7 Deadlocks (chapter 7)

Deadlocks. Bridge Crossing Example. The Problem of Deadlock. Deadlock Characterization. Resource-Allocation Graph. System Model

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

UNIT-5 Q1. What is deadlock problem? Explain the system model of deadlock.

Chapter 6: Synchronization. Operating System Concepts 8 th Edition,

The Deadlock Problem (1)

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

System Model. Types of resources Reusable Resources Consumable Resources

Chapter 7: Deadlocks

Deadlock Prevention. Restrain the ways request can be made. Mutual Exclusion not required for sharable resources; must hold for nonsharable resources.

Chapter 7: Deadlocks. Operating System Concepts 8th Edition, modified by Stewart Weiss

Principles of Operating Systems

CSE Opera+ng System Principles

CHAPTER 7 - DEADLOCKS

Chapter 8: Deadlocks. Operating System Concepts with Java

Module 7: Deadlocks. The Deadlock Problem

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

Module 7: Deadlocks. System Model. Deadlock Characterization. Methods for Handling Deadlocks. Deadlock Prevention. Deadlock Avoidance

Deadlocks. Deadlock Overview

Deadlock. Operating Systems. Autumn CS4023

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

Interprocess Communication By: Kaushik Vaghani

Principles of Operating Systems

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

Operating Systems 2015 Spring by Euiseong Seo DEAD LOCK

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Last Class: Monitors. Real-world Examples

The Deadlock Problem

CS420: Operating Systems. Deadlocks & Deadlock Prevention

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

CS307: Operating Systems

Deadlock. Concepts to discuss. A System Model. Deadlock Characterization. Deadlock: Dining-Philosophers Example. Deadlock: Bridge Crossing Example

ICS Principles of Operating Systems. Lectures Set 5- Deadlocks Prof. Nalini Venkatasubramanian

COMP 3713 Operating Systems Slides Part 3. Jim Diamond CAR 409 Jodrey School of Computer Science Acadia University

Deadlocks. Prepared By: Kaushik Vaghani

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 7 Deadlocks. Zhi Wang Florida State University

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

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

OPERATING SYSTEMS. Deadlocks

Deadlock Risk Management

Deadlocks. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Contents. Chapter 8 Deadlocks

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

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

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

Deadlocks. Operating System Concepts - 7 th Edition, Feb 14, 2005

Lecture 3: Synchronization & Deadlocks

Process Synchronization: Semaphores. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6.

Deadlocks. Dr. Yingwu Zhu

Chapter 6: Process Synchronization

Deadlocks. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

PESIT Bangalore South Campus

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

UNIT-3 DEADLOCKS DEADLOCKS

CS370 Operating Systems

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Operating Systems Antonio Vivace revision 4 Licensed under GPLv3

Module 6: Deadlocks. Reading: Chapter 7

UNIT:2. Process Management

Roadmap. Deadlock Prevention. Deadlock Prevention (Cont.) Deadlock Detection. Exercise. Tevfik Koşar. CSE 421/521 - Operating Systems Fall 2012

Chapter 6: Process Synchronization

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Chapter 7: Process Synchronization!

Chapter 7: Deadlocks CS370 Operating Systems

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition

Process Synchronization

CS420: Operating Systems. Process Synchronization

Fall 2015 COMP Operating Systems. Lab 06

Deadlock Risk Management

Operating System: Chap7 Deadlocks. National Tsing-Hua University 2016, Fall Semester

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

Process Synchronization

Transcription:

What is the Race Condition? And what is its solution? Race Condition: Where several processes access and manipulate the same data concurrently and the outcome of the execution depends on the particular order in which the access takes place. Its solution is that these processes must be synchronized in some way. We must guarantee that only one process at a time can be manipulating this resource. What is a critical section? And what is the critical section problem? Critical section: It is a segment of code for each process in which the process may be changing common variables, updating a table, writing a file, and so on. Critical section problem: It is to design a protocol that the processes can use to cooperate. Each process must request permission to enter its critical section. When one process is executing in its critical section, no other process is to be allowed to execute in its critical section. The critical section consists of entry section that implements the request, the critical section itself, en exit section, and the reminder section. 1

What is a critical section problem s solution must satisfy? A solution to the critical section problem must satisfy the following: Mutual exclusion: When a process p is executing in the critical section, no other processes can be executing in their critical sections. Progress: If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indefinitely. Bound waiting: A bound must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted. Give solutions to the critical section problem Solutions to the critical section problem: Peterson s solution. Synchronization hardware. Semaphore. Discuss the Peterson s solution to the critical section problem. It is a classic software-based solution to the critical-section problem. It provides a good algorithmic description of solving the criticalsection problem. It is a two process solution. The 2 processes share the following variables (int turn; bool flag[2]). The turn variable determines which process whose turn to enter its critical section. The flag[2] array determines which process is ready to enter its critical section. software-based solutions such as Peterson s are not guaranteed to work on modern computer architectures. 2

Discuss the Synchronization Hardware solution to the critical section problem Race conditions are prevented by requiring that critical regions be protected by locks. That is, a process must acquire a lock before entering a critical section; it releases the lock when it exits the critical section. 3

Discuss the Semaphore solution to the critical section problem Semaphore: It is an integer variable that, apart from initialization, is accessed only through 2 atomic operations: Wait ( ) and Signal ( ). Wait ( ): was originally termed P (to test). Signal ( ): was originally called V (to increment). All modifications to the integer variable of the semaphore in the Wait ( ) and Signal ( ) operations must be executed indivisibly. What are the types of semaphores? There are two types of semaphores: Binary Semaphore: Integer value that can range only between 0 and 1and also known as mutex locks. Counting Semaphores: Integer value that may be greater than 1and is used to allocate a resource from a pool of identical resources. What is the busy waiting problem? Busy Waiting: While a process is in its critical section, any other process that tries to enter its critical section must loop continuously in the entry code. 4

Mutual-exclusion implementation with semaphores How to overcome the busy waiting problem? To overcome the busy waiting problem we must modify the definition of the Wait ( ) and Signal ( ) processes as following: With each semaphore there is an associating waiting queue. Each entry in the waiting queue has 2 data items: - Value of type integer. - Pointer to next record in the list. We use two operations: - Block: this operation places a process into a waiting queue associated with the semaphore and the process state is switched to the waiting state. - Wake Up: this operation removes one of the processes from the waiting queue and places it in the ready queue and the process state is switched to the ready state. 5

What is Deadlock and Starvation? Deadlock: Two or more processes are waiting indefinitely for an event that can be caused by only one of the waiting processes. Starvation: Indefinite blocking. A process may never be removed from the semaphore queue in which it is suspended. What is the Deadlock problem? Deadlock problem: A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set. Discuss the system model of the deadlock problem The System has a set of resource types R1, R2, Ri. Each resource type Ri has Wi instances. Each process utilizes a resource as follows (Request Use Release). 6

What are the conditions for deadlock? There are 4 conditions that must occur simultaneously to cause deadlock to occur: Mutual exclusion: only one process at a time can use a resource. Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes. No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task. Circular wait: there exists a set {P 0, P 1,, P 0 } of waiting processes such that P 0 is waiting for a resource that is held by P 1, P 1 is waiting for a resource that is held by P 2,, P n 1 is waiting for a resource that is held by P n, and Pn is waiting for a resource that is held by P 0. What is the Resource Allocation Graph? Resource Allocation Graph: It is a directed graph by which a deadlock problem can be described more precisely. It consists of a set of vertices V and a set of edges E. The set V is partitioned into two types of nodes P (the set of all active processes P1, P2 ), and R (the set of all available resource types R1, R2 ). The set E is partitioned into two types of directed edges, request edges from process Pi to a resource type Ri, and a set of directed assignment edges from a resource type Ri to a process Pi. 7

Some basic facts: If a graph contains no cycles, then no deadlock exists. If a graph contains cycles, and only one instance per resource type is available, then deadlock exists. If a graph contains cycles, and several instances per resource type are available, then possibility of deadlock. Resource Allocation Graph With Deadlock Graph with a Cycle but no Deadlock 8

How a Deadlock can be prevented? A Deadlock can be prevented by making at least one of its conditions cannot hold, as follows: Mutual exclusion: not required for sharable resources, but required for non sharable resources. Hold and wait: Guarantees that whenever a process holds a resource, it does not hold any other resources. No preemption: If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released and preempted resources are added to the list of resources for which the process is waiting. Circular waiting: impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration. How Deadlock can be avoided? Deadlock avoidance requires the system to have some prior information to be available: Each process declares the maximum number of resources of each type that it may need. The deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that there can never be a circularwait condition. Resource-allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes. Discuss the Deadlock avoidance algorithm Safe state: A state is safe if the system can allocate resources to each process (up to its claimed maximum) and still avoid a deadlock. Unsafe state: A state is unsafe if the system cannot prevent processes from requesting resources such that a deadlock occurs. 9

Assumption: For every process, the maximum resource claims are know a priori. Idea: Only grant resource requests that cannot lead to a deadlock situation. Single instance of a resource type by using a resource-allocation graph. Unsafe State in Resource-Allocation Graph How a system can detect a deadlock? To detect a deadlock, the system may provide: An algorithm to examine the state of the system to determine wether or not a deadlock occurs. An algorithm to recover from the deadlock. Resource-Allocation Graph and wait-for graph 10

How the system can recover from a deadlock? The system can recover from a deadlock either by process termination or by resource preempting. Discuss each of the mechanisms a system can use to recover from a deadlock? Process termination: Abort all deadlocked processes or abort on process at a time until the deadlock cycle is eliminated. Resources preempting: By selecting a victim process to minimize cost, then rolling back to some safe state and restart the process for that state. Starvation may occur as the same process may always be picked as a victim, include number of rollback in cost factor. In which order should we choose a process to abort? A process chosen to be aborted according to the following order: 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? 11