Chapter 2.3 : Interprocess Communication

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

Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Operating Systems Part III: Process Management (Process Synchronization)
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.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 2 Processes and Threads
Chapter 6: Process Synchronization
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
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.
Chapter 3 The Critical Section Problem
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.
Avishai Wool lecture Introduction to Systems Programming Lecture 4 Inter-Process / Inter-Thread Communication.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Objectives Understand.
1 Chapter 6: Concurrency: Mutual Exclusion and Synchronization Operating System Spring 2007 Chapter 6 of textbook.
Synchronization Solutions
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
02/19/2007CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Adopted from and based on Textbook: Operating System Concepts – 8th Edition, by Silberschatz, Galvin and Gagne Updated and Modified by Dr. Abdullah Basuhail,
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Concurrency, Mutual Exclusion and Synchronization.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Process Synchronization Continued 7.2 Critical-Section Problem 7.3 Synchronization Hardware 7.4 Semaphores.
Midterm 1 – Wednesday, June 4  Chapters 1-3: understand material as it relates to concepts covered  Chapter 4 - Processes: 4.1 Process Concept 4.2 Process.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
1 Chapter 2.3 : Interprocess Communication Process concept  Process concept  Process scheduling  Process scheduling  Interprocess communication Interprocess.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
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 6 – Process Synchronisation (Pgs 225 – 267)
Process Synchronization Tanenbaum Ch 2.3, 2.5 Silberschatz Ch 6.
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 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-5 Process Synchronization Department of Computer Science and Software.
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
Concurrency in Shared Memory Systems Synchronization and Mutual Exclusion.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Process Synchronization CS 360. Slide 2 CS 360, WSU Vancouver Process Synchronization Background The Critical-Section Problem Synchronization Hardware.
1 Processes and Threads Part II Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Process Synchronization. Objectives To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data To.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
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
Chapter 5: Process Synchronization
Process Synchronization: Semaphores
Background on the need for Synchronization
Chapter 5: Process Synchronization
Chapter 5: Process Synchronization
Concurrency: Mutual Exclusion and Synchronization
Topic 6 (Textbook - Chapter 5) Process Synchronization
Lecture 22 Syed Mansoor Sarwar
Lecture 2 Part 2 Process Synchronization
Concurrency: Mutual Exclusion and Process Synchronization
CSE 153 Design of Operating Systems Winter 19
CS333 Intro to Operating Systems
Chapter 6: Synchronization Tools
Presentation transcript:

Chapter 2.3 : Interprocess Communication Process concept  Process scheduling  Interprocess communication Deadlocks Threads Ceng 334 - Operating Systems

Producer - Consumer Problem Producer Process Consumer Process Produce Put in buffer Consume Get from buffer BUFFER Buffer is shared (ie., it is a shared variable) Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Progress in time….. Producer Consumer 1 2 c2 p1 p4 p3 p2 4 3 t Buffer 3 instead of 2! c1 Both processes are started at the same time and consumer uses some old value initially Ceng 334 - Operating Systems

Ceng 334 - Operating Systems A Race Condition Because of the timing and which process starts first There is a chance that different executions may end up with different results Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Critical Sections Critical Section A section of code in which the process accesses and modifies shared variables Mutual Exclusion A method of preventing for ensuring that one (or a specified number) of processes are in a critical section Ceng 334 - Operating Systems

Why Processes Need to Communicate? To synchronize their executions To exchange data and information Ceng 334 - Operating Systems

Rules to Form Critical Sections 1. No two processes may be simultaneously inside their CS (mutual exclusion) 2. No assumptions are made about relative process speeds or number of CPUs 3. A process outside a CS should not block other processes 4. No process should wait forever before entering its CS Ceng 334 - Operating Systems

Mutual Exclusion Problem : Starvation Also known as Indefinite Postponement Definition Indefinitely delaying the scheduling of a process in favour of other processes Cause Usually a bias in a systems scheduling policies (a bad scheduling algorithm) Solution Implement some form of aging Ceng 334 - Operating Systems

Another Problem : Deadlocks Two (or more) processes are blocked waiting for an event that will never occur Generally, A waits for B to do something and B is waiting for A Both are not doing anything so both events never occur Ceng 334 - Operating Systems

How to Implement Mutual Exclusion Three possibilities Application: programmer builds some method into the program Hardware: special h/w instructions provided to implement ME OS: provides some services that can be used by the programmer All schemes rely on some code for enter_critical_section, and exit_critical_section These "functions" enclose the critical section Ceng 334 - Operating Systems

Application Mutual Exclusion Application Mutual Exclusion is implemented by the programmer hard to get correct, and very inefficient All rely on some form of busy waiting (process tests a condition, say a flag, and loops while the condition remains the same) Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Example Producer produce If lock = 1 loop until lock = 0 lock=1 put in buffer lock=0 Consumer get from buffer consume Ceng 334 - Operating Systems

Hardware ME : Test and Set Instruction Perform an indivisible x:=r and r:=1 x is a local variable r is a global register set to 0 initially repeat (test&set(x)) until x = 0; < critical section > r:= 0; Ceng 334 - Operating Systems

Hardware ME : Exchange Instruction Exchange: swap the values of x and r x is a local variable r is a global register set to 1 initially x:= 0; repeat exchange(r, x) until x = 1; < critical section > exchange(r, x); Note: r:= 0 and x:= 1 when the process is in CS Ceng 334 - Operating Systems

Hardware ME Characteristics Advantages can be used by a single or multiple processes (with shared memory) simple and therefore easy to verify can support multiple critical sections Disadvantages busy waiting is used starvation is possible deadlock is possible (especially with priorities) Ceng 334 - Operating Systems

Another Hardware ME : Disabling Interrupts On a single CPU only one process is executed Concurrency is achieved by interleaving execution (usually done using interrupts) If you disable interrupts then you can be sure only one process will ever execute One process can lock a system or degrade performance greatly Ceng 334 - Operating Systems

Mutual Exclusion Through OS Semaphores Message passing Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Semaphores Major advance incorporated into many modern operating systems (Unix, OS/2) A semaphore is a non-negative integer that has two indivisible, valid operations Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Semaphore Operations Wait(s) If s > 0 then s:= s - 1 else block this process Signal(s) If there is a blocked process on this semaphore then wake it up else s:= s + 1 Ceng 334 - Operating Systems

Ceng 334 - Operating Systems More on Semaphores The other valid operation is initialisation Two types of semaphores binary semaphores can only be 0 or 1 counting semaphores can be any non-negative integer Semaphores are an OS service implemented using one of the methods shown already usually by disabling interrupts for a very short time Ceng 334 - Operating Systems

Producer - Consumer Problem: Solution by Semaphores Wait(mutex) Put in buffer Signal(mutex) Wait(mutex) Get from buffer Signal(mutex) Consume CS Initially semaphore mutex is 1 Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Another Example Three processes all share a resource on which one draws an A one draws a B one draws a C Implement a form of synchronization so that the output appears ABC think(); draw_A(); draw_B(); draw_C(); Process A Process B Process C Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Semaphore b = 0, c = 0; think(); draw_A(); signal(b); wait(b); draw_B(); signal(c); wait(c); draw_C(); Process A Process B Process C Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Message Passing Provides synchronization and information exchange Message Operations: send(destination, &message) receive (source, &message) Ceng 334 - Operating Systems

Producer - Consumer Problem Using Messages #define N 100 /*number of message slots*/ producer( ) {int item; message m; while (TRUE) { produce_item(&item); receive(consumer,&m); build_message(&m, item); send(consumer,&m); }} Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Consumer( ) {int item; message m; for (i=0; i<N; i++) send(producer,&m); while (TRUE) { receive(producer,&m); extract_item(&m,&item); send(producer,&m); consume_item(item); }} Ceng 334 - Operating Systems