Operating Systems COMP 4850/CISG 5550 Interprocess Communication, Part II Dr. James Money.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Synchronization and Deadlocks
Prepared By Sarath S Menon S6 CSE.  Imagine a scenario in which there exists two Distinct processes both operating on a single shared data area.  One.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 2 Processes and Threads
EEE 435 Principles of Operating Systems Interprocess Communication Pt II (Modern Operating Systems 2.3)
CY2003 Computer Systems Lecture 05 Semaphores - Theory.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 13: October 12, 2010 Instructor: Bhuvan Urgaonkar.
1 Threads CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5.
Concurrency, Race Conditions, Mutual Exclusion, Semaphores, Monitors, Deadlocks Chapters 2 and 6 Tanenbaum’s Modern OS.
Interprocess Communication
Chapter 2: Processes Topics –Processes –Threads –Process Scheduling –Inter Process Communication (IPC) Reference: Operating Systems Design and Implementation.
Avishai Wool lecture Introduction to Systems Programming Lecture 4 Inter-Process / Inter-Thread Communication.
1 CS318 Project #3 Preemptive Kernel. 2 Continuing from Project 2 Project 2 involved: Context Switch Stack Manipulation Saving State Moving between threads,
5.6.2 Thread Synchronization with Semaphores Semaphores can be used to notify other threads that events have occurred –Producer-consumer relationship Producer.
Synchronization Principles. Race Conditions Race Conditions: An Example spooler directory out in 4 7 somefile.txt list.c scores.txt Process.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
Semaphores, mutexes and condition variables. semaphores Two types – Binary – 0 or 1 – Counting 0 to n Wait – decrements > 0 forces a wait Post or signal.
1 CS 333 Introduction to Operating Systems Class 4 – Synchronization Primitives Semaphores Jonathan Walpole Computer Science Portland State University.
Chapter 2.3 : Interprocess Communication
Semaphores CSCI 444/544 Operating Systems Fall 2008.
Jonathan Walpole Computer Science Portland State University
Jonathan Walpole Computer Science Portland State University
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
1 Outline Processes Threads Inter-process communication (IPC) Classical IPC problems Scheduling.
1 Interprocess Communication Race Conditions Two processes want to access shared memory at same time.
1 Race Conditions/Mutual Exclusion Segment of code of a process where a shared resource is accessed (changing global variables, writing files etc) is called.
OPERATING SYSTEM LESSON 6 INTERPROCESS COMMUNICATION.
Semaphores Questions answered in this lecture: Why are semaphores necessary? How are semaphores used for mutual exclusion? How are semaphores used for.
1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Semaphores. Readings r Silbershatz: Chapter 6 Mutual Exclusion in Critical Sections.
Semaphores and Bounded Buffer Andy Wang Operating Systems COP 4610 / CGS 5765.
CY2003 Computer Systems Lecture 06 Interprocess Communication Monitors.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 14: October 14, 2010 Instructor: Bhuvan Urgaonkar.
Semaphores and Bounded Buffer. Semaphores  Semaphore is a type of generalized lock –Defined by Dijkstra in the last 60s –Main synchronization primitives.
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
TANNENBAUM SECTION 2.3 INTERPROCESS COMMUNICATION3 OPERATING SYSTEMS.
CIS Operating Systems Synchronization Professor Qiang Zeng Fall 2015.
Operating Systems Inter-Process Communications. Lunch time in the Philosophy Department. Dining Philosophers Problem (1)
1 Interprocess Communication Yücel Saygın | These slides are based on your text book and on the slides prepared by Andrew S. Tanenbaum.
1 Processes and Threads Part II Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
1 5-High-Performance Embedded Systems using Concurrent Process (cont.)
Process Synchronization. Objectives To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data To.
Operating System Concepts and Techniques Lecture 14 Interprocess communication-3 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and.
Semaphores Reference –text: Tanenbaum ch
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Mutual Exclusion Mutexes, Semaphores.
CS 311/350/550 Semaphores. Semaphores – General Idea Allows two or more concurrent threads to coordinate through signaling/waiting Has four main operations.
Interprocess Communication Race Conditions
CPS110: Reader-writer locks
PARALLEL PROGRAM CHALLENGES
Background on the need for Synchronization
Interprocess Communication (3)
Operating Systems CMPSC 473
5-High-Performance Embedded Systems using Concurrent Process (cont.)
Lecture 13: Producer-Consumer and Semaphores
Semaphores and Bounded Buffer
Operating Systems Chapter 2: Processes and Threads
Threading And Parallel Programming Constructs
Process Synchronization
Concurrency: Mutual Exclusion and Process Synchronization
CSE 451: Operating Systems Autumn Lecture 8 Semaphores and Monitors
Lecture 13: Producer-Consumer and Semaphores
CSE 153 Design of Operating Systems Winter 19
CSE 153 Design of Operating Systems Winter 2019
CS333 Intro to Operating Systems
Interprocess Communication & Synchronization
Presentation transcript:

Operating Systems COMP 4850/CISG 5550 Interprocess Communication, Part II Dr. James Money

Semaphores In 1965, Dijkstra introduced the idea of a semaphore for the producer-consumer problem. In 1965, Dijkstra introduced the idea of a semaphore for the producer-consumer problem. A semaphore is an integer variable to count the number of wakeups. A semaphore is an integer variable to count the number of wakeups. The semaphore is 0 if there are no wakeups saved, or some positive value is there are some waiting. The semaphore is 0 if there are no wakeups saved, or some positive value is there are some waiting.

Semaphores There are two operations on the semaphore: There are two operations on the semaphore: –up –down These generalize sleep and wakeup These generalize sleep and wakeup

Semaphore - down The down function does the following: The down function does the following: –If the value of the semaphore is greater than 0, it decrements the value –If the value is 0, the process it put to sleep without completing down –This is done as an atomic operation

Semaphore – up The up function does the following: The up function does the following: –Increments the value of the semaphore –If one of the processes running down are sleeping, it is chosen by the system to complete it’s down operation. In this case, the semaphore remains 0.

Solving P-C Problem with Semaphores We can solve the producer-consumer problem with semaphores We can solve the producer-consumer problem with semaphores We need three semaphores: We need three semaphores: –full – counting the number of slots full –empty – counting the slots that are empty –mutex – to ensure the producer and consumer do not access the buffer at the same time

P-C Problem with Semaphores Initially: Initially: –full = 0 –empty=N –mutex – 1 Semaphores that are set to 1, and used by 2+ processes to ensure only one of them enter their critical region at a time are called binary semaphores. Semaphores that are set to 1, and used by 2+ processes to ensure only one of them enter their critical region at a time are called binary semaphores.

P-C Problem with Semaphores

Mutexes When the counting ability of a semaphore is not needed, we use a binary version called a mutex. When the counting ability of a semaphore is not needed, we use a binary version called a mutex. A mutex is a variable that can be in one of two states: A mutex is a variable that can be in one of two states: –locked –unlocked

Mutexes There are two functions: There are two functions: –mutex_lock –mutex_unlock

mutex_lock If the mutex is unlocked, the mutex is locked and the program can enter its critical regions If the mutex is unlocked, the mutex is locked and the program can enter its critical regions If the mutex is locked, the calling thread is blocked until mutex_unlock has been called by another thread If the mutex is locked, the calling thread is blocked until mutex_unlock has been called by another thread If multiple threads are blocked mutex_lock, then one of them is chosen to be given the lock. If multiple threads are blocked mutex_lock, then one of them is chosen to be given the lock.

mutex_unlock mutex_unlock setp the mutex to 0, and unblocks a process if needed mutex_unlock setp the mutex to 0, and unblocks a process if needed

Mutexes Mutexes are simple enough to implement in user space:

Message Passing When multiple machines are involved, none of the prior solutions work. When multiple machines are involved, none of the prior solutions work. This new IPC method is called message passing. This new IPC method is called message passing. There are two functions: There are two functions: –send(destination, &message); –receive(source,&message);

Message Passing Design Issues: Design Issues: –Messages can be lost – there must be some acknowledgement of the received message –What if a message is received twice? Use sequence numbers or message tags –How to name processes and ensure authentication?

P-C Problem with Message Passing

Barriers Barriers are used when one process may not proceed until another process reaches a certain point Barriers are used when one process may not proceed until another process reaches a certain point When a process reaches a barrier call, it blocks until all the processes call barrier When a process reaches a barrier call, it blocks until all the processes call barrier

Barriers