Concurrency: Mutual Exclusion and Synchronization Why we need Mutual Exclusion? Classical examples: Bank Transactions:Read Account (A); Compute A = A +

Slides:



Advertisements
Similar presentations
1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
Advertisements

Operating Systems Part III: Process Management (Process Synchronization)
CHAPTER3 Higher-Level Synchronization and Communication
1 Chapter 5 Concurrency: Mutual Exclusion and Synchronization Principals of Concurrency Mutual Exclusion: Hardware Support Semaphores Readers/Writers Problem.
Global Environment Model. MUTUAL EXCLUSION PROBLEM The operations used by processes to access to common resources (critical sections) must be mutually.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 6: Process Synchronization
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
Operating Systems Operating Systems - Winter 2009 Chapter 2 - Processes Vrije Universiteit Amsterdam.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles Seventh Edition By William Stallings.
Concurrency: mutual exclusion and synchronization Slides are mainly taken from «Operating Systems: Internals and Design Principles”, 8/E William Stallings.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles Seventh Edition By William Stallings.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 13: October 12, 2010 Instructor: Bhuvan Urgaonkar.
Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 91 Today’s class Mutual exclusion and synchronization 
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Enforcing Mutual Exclusion Message Passing. Peterson’s Algorithm for Processes P0 and P1 void P0() { while( true ) { flag[ 0 ] = false; /* remainder */
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization
1 Semaphores Special variable called a semaphore is used for signaling If a process is waiting for a signal, it is suspended until that signal is sent.
Concurrency CS 510: Programming Languages David Walker.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
Concurrency : Mutual Exclusion and Synchronization
1 Chapter 6: Concurrency: Mutual Exclusion and Synchronization Operating System Spring 2007 Chapter 6 of textbook.
Lecture 4: Parallel Programming Models. Parallel Programming Models Parallel Programming Models: Data parallelism / Task parallelism Explicit parallelism.
Operating System 5 CONCURRENCY: MUTUAL EXCLUSION AND SYNCHRONIZATION.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings 1.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago.
Concurrency, Mutual Exclusion and Synchronization.
Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Introduction to Concurrency.
6.3 Peterson’s Solution The two processes share two variables: Int turn; Boolean flag[2] The variable turn indicates whose turn it is to enter the critical.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 7 -1 CHAPTER 7 PROCESS SYNCHRONIZATION CGS Operating System Concepts UCF, Spring 2004.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Lecture 8: Concurrency: Mutual Exclusion and Synchronization(cont.) Advanced Operating System Fall 2009.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Operating System Chapter 5. Concurrency: Mutual Exclusion and Synchronization Lynn Choi School of Electrical Engineering.
1 Processes and Threads Part II Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Synchronicity II Introduction to Operating Systems: Module 6.
Distributed Mutual Exclusion Synchronization in Distributed Systems Synchronization in distributed systems are often more difficult compared to synchronization.
Gokul Kishan CS8 1 Inter-Process Communication (IPC)
Readers/Writers Problem  Multiple processes wanting to read an item, and one or more needing to write (Think of airline reservations…)  Rather than enforce.
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Interprocess Communication Race Conditions
Operating Systems Chapter 2 - Processes Vrije Universiteit Amsterdam
Chapter 5 Concurrency: Mutual Exclusion and Synchronization
G.Anuradha Reference: William Stallings
Concurrency These slides are intended to help a teacher develop a presentation. This PowerPoint covers the entire chapter and includes too many slides.
Inter-Process Communication and Synchronization
Lecture 16: Readers-Writers Problem and Message Passing
Concurrency: Mutual Exclusion and Synchronization
Chapter 5: Process Synchronization
Background and Motivation
Lecture 16: Readers-Writers Problem and Message Passing
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
Operating System 5 CONCURRENCY: MUTUAL EXCLUSION AND SYNCHRONIZATION
Presentation transcript:

Concurrency: Mutual Exclusion and Synchronization Why we need Mutual Exclusion? Classical examples: Bank Transactions:Read Account (A); Compute A = A ;Compute A = A – 500;Write Account (A); Keep A = B all the time A = A + 1;A = 2 * A; B = B + 1;B = 2 * B; Wrong results if mutual exclusion is not enforced!

Disable Interrupt Software Solution Dekker’s Algorithm Peterson’s Algorithm Hardware Solution Disable Interrupt Test & Set Exchange Instruction

Monitors Semaphores is a powerful and flexible tool for enforcing mutual exclusion and for coordinating processes. It may be difficult to produce a correct program and very difficult to debug. The difficulty is that wait and signal operations will be scattered throughout a program and it is not easy to see the overall effect of these operations on the semaphores they affect. A monitor is a programming language construct that provides equivalent functionality to that of semaphores but easier to control. Monitors is implemented in: –Concurrent Pascal –Pascal-Plus –Modula-2, Module-3 –Ada –As a programming library

Monitors (continue) Monitors can lock on any object. One may want to lock all linked list with one lock; or lock a particular linked list by one lock; or lock an element of a particular linked list by one lock. Monitor with Signal –cwait(condition): Suspended execution of the calling process on a condition. The monitor is now available for use by another process. –csignal(condition): Resume execution of some process suspended after a cwait on the same condition. If there are several such processes, choose one of them; if there is no such process, do nothing. A monitor is a software module consisting of one or more procedures, an initialization sequence, and local data. –The local data variables are accessible only by the monitor’s procedures and not by any external procedures. –A process enters the monitor by invoking one of its procedures. –Only one process may be executing in the monitor at a time; any other process that has invoked the monitor is suspended, waiting for the monitor to become available.

Message Passing Two fundamental requirements must be satisfied when processes interact: synchronization and communication. Message passing is a common approach for distributed systems. It is normally provided in the form of a pair of primitives: –send(destination, message) –receive(source, message) Major design characteristics of message systems for Inter-processor Communication and Synchronization: –Synchronization Send : blocking vs. non-blocking Receive : blocking, non-blocking, test for arrival –Addressing: Direct –Send –Receive : explicit vs. implicit Indirect –Static, dynamic, ownership –Format: message content; Length -- fixed vs. variable –Queuing Discipline: FIFO, Priority Driven

Readers/Writers Problem The readers/writers problem is defined as follows: There is a data shared among a number of processes. The data area could be a file, a block of main memory, or even a back of processor registers. There are a number of processes that only read the data (readers) and a number of processes that only write to the data (writers) The following conditions must be satisfied: –1. Any number of readers may read the data at the same time. –2. Only one writer at a time may write to the data. –3. If a writer is writing to the data, no reader may read it. Two observations: –Readers have priority (writers might starve) –Writers have priority