CY2003 Computer Systems Lecture 06 Interprocess Communication Monitors.

Slides:



Advertisements
Similar presentations
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Advertisements

Ch 7 B.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
EEE 435 Principles of Operating Systems Interprocess Communication Pt II (Modern Operating Systems 2.3)
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
CY2003 Computer Systems Lecture 05 Semaphores - Theory.
Classic Synchronization Problems
Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 91 Today’s class Mutual exclusion and synchronization 
Synchronization: semaphores and some more stuff 1 Operating Systems, 2011, Danny Hendler & Amnon Meisels.
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.
Interprocess Communication
Operating Systems Process Synchronization. Too Much Pizza 3:00 3:05 3:10 3:15 3:20 3:25 3:30 Person A Look in fridge. Pizza! Leave for store. Arrive at.
Avishai Wool lecture Introduction to Systems Programming Lecture 4 Inter-Process / Inter-Thread Communication.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
Review: Producer-Consumer using Semaphores #define N 100// number of slots in the buffer Semaphore mutex = 1;// controls access to critical region Semaphore.
Synchronization and IPC 1 CS502 Spring 2006 More on Synchronization Interprocess Communication (IPC) CS-502 Spring 2006.
CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 1 More on Synchronization Interprocess Communication (IPC) CS-3013 & CS-502 Summer 2006.
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.
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.
Chapter 2.3 : Interprocess Communication
Semaphores The producer-consumer problem using semaphores.
1 Outline Processes Threads Inter-process communication (IPC) Classical IPC problems Scheduling.
Operating Systems Process Synchronization (Ch )
COMP5102 Lecture 4 Operating Systems (OS) Inter-process Communication phones off (please)
Operating System I Process Synchronization. Too Much Pizza 3:00 3:05 3:10 3:15 3:20 3:25 3:30 Person A Look in fridge. Pizza! Leave for store. Arrive.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings 1.
Semaphores. Readings r Silbershatz: Chapter 6 Mutual Exclusion in Critical Sections.
1 Processes Chapter Processes 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 Processes, Threads, Race Conditions & Deadlocks Operating Systems Review.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
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.
4061 Session 21 (4/3). Today Thread Synchronization –Condition Variables –Monitors –Read-Write Locks.
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.
CE Operating Systems Lecture 13 Linux/Unix interprocess communication.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Synchronization.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
TANNENBAUM SECTION 2.3 INTERPROCESS COMMUNICATION4 OPERATING SYSTEMS.
Synchronization: semaphores and some more stuff 1 Operating Systems, 2014, Meni Adler, Danny Hendler & Amnon Meisels.
Operating Systems COMP 4850/CISG 5550 Interprocess Communication, Part II Dr. James Money.
1 Processes and Threads Part II Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
1 Advanced Operating Systems - Fall 2009 Lecture 7 – February 2, 2009 Dan C. Marinescu Office: HEC 439 B. Office hours:
Operating System Concepts and Techniques Lecture 13 Interprocess communication-2 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and.
1 5-High-Performance Embedded Systems using Concurrent Process (cont.)
Operating System Concepts and Techniques Lecture 14 Interprocess communication-3 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and.
Semaphores Reference –text: Tanenbaum ch
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems The producer consumer problem Monitors and messaging.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Interprocess Communication Race Conditions
Synchronization: semaphores and some more stuff
Semaphores Reference text: Tanenbaum ch
Interprocess Communication (3)
CS510 Operating System Foundations
Lecture 13: Producer-Consumer and Semaphores
Concurrency: Mutual Exclusion and Synchronization
Chapter 5: Process Synchronization
Process Synchronization
Lecture 13: Producer-Consumer and Semaphores
CSE 153 Design of Operating Systems Winter 2019
Semaphores Reference text: Tanenbaum ch
Synchronization, Part 2 Semaphores
Presentation transcript:

CY2003 Computer Systems Lecture 06 Interprocess Communication Monitors

© JMU, 2004CY2003- Week 062 Overview Recall: Semaphores theory Monitors –Solving the producer-consumer problem Message passing –solving synchronisation problems Software interrupts –UNIX signals

Recall: Semaphores

© JMU, 2004CY2003- Week 064 Recall Semaphores A semaphore has two operations defined –down(s) if (s > 0) s = s -1 else, sleep (blocks) –up(s) if there are processes waiting, then one is woken up if not, s = s +1 Both these are guaranteed to be an atomic action –no other process can access the semaphore until the operation has completed or blocked

© JMU, 2004CY2003- Week 065 Semaphore Implementation The key to the successful functioning of the semaphore is the concept of atomicity –as the semaphore is a closely controlled operating system primitive (e.g. system call) it can safely be implemented by disabling interrupts an application cannot abuse the interrupt handling

© JMU, 2004CY2003- Week 066 Semaphore Difficulties Recall the use of semaphores to solve the producer-consumer problem while ( TRUE ) { produce_item(item); down(empty); down(mutex); enter_item(item); up(mutex); up(full); } producer while ( TRUE ) { down(full); down(mutex); remove_item(item); up(mutex); up(empty); consume_item(item); } consumer But! If the order of the down ’s in the producer code are reversed, then the solution is ‘broken’ if the buffer was full, the producer would perform a down on mutex and then block in the down on empty the consumer would then block in the down on mutex –both processes would stay blocked forever!

© JMU, 2004CY2003- Week 067 Semaphore Limitations Semaphores are low-level constructs and so are difficult to program in practice –higher level constructs have been proposed, but these require specially developed languages (i.e. not C!)

Monitors

© JMU, 2004CY2003- Week 069 Monitors To overcome the problem of semaphores, a higher level synchronisation primitive called monitor was introduced Monitor is a collection of procedures, variable, and data structure –Processes can call the monitor whenever they like –They cannot directly access the monitor’s internal structure, from procedures outside the internal structure Only one process can be active in a monitor

© JMU, 2004CY2003- Week 0610 Monitors Monitors ensures mutual exclusion and there is no need to program it. However, there should be some way to ensure that processes block when they cannot proceed. –This is performed through condition variables and with two operations which are wait and signal. When monitor procedure discovers it cannot continue (e.g. the producer discovers that the buffer is full), it does a wait on some condition variables (e.g. full).

© JMU, 2004CY2003- Week 0611

© JMU, 2004CY2003- Week 0612 Monitors Condition full, empty; int count; Monitor ProducerConsumer void insert(int item) { if (count == N) wait(full); inset_item(item); count = count + 1; if (count ==1) signal(empty); } int remove() { if (count == 0) wait(empty); item = remove_item(); count = count - 1; if (count == N-1) signal(full); return item; }

© JMU, 2004CY2003- Week 0613 Monitors while ( TRUE ) { item = produce_item(); ProducerConsumer.insert(item); } producer while ( TRUE ) { item = ProducerConsumer.remove(); consume_item(item); } consumer The wait and signal operations are similar to the sleep and weekup system calls. –however without suffering from their fatal deadlock

Message Passing

© JMU, 2004CY2003- Week 0615 Message Passing Two message passing primitives are needed –send (destination, message) sends a message to a given destination may block until the message is successfully sent –receive (source, message) receives a message from a given source this will usually block until a message is received Although these are conceptually simple, there are many complex design issues to be considered –source and destination addresses may be on different machines across a network: how are they named? –how are links established? what are their capacities?

© JMU, 2004CY2003- Week 0616 A Producer-Consumer Solution Assume that messages are a fixed size and that messages sent but not received are automatically stored by the operating system for future receipt there are 100 slots in our message buffer int item; message m, empty; while ( TRUE ) { produce_item(item); receive(consumer, empty); build_message(m, item); send(consumer, m); } producer int item; message m, empty; for ( i= 0; i < 100; i++ ) send(producer, empty); while ( TRUE ) { receive(producer, m); extract_item(m, item); send(producer, empty); consume_item(item); } consumer

© JMU, 2004CY2003- Week 0617 Exception Conditions A number of problems can occur with messages –process termination sender or receiver terminates before a message is processed the OS needs to catch these conditions to prevent deadlock –lost messages a message may be lost in the communication network one solution is to require acknowledgement messages –a message is resent if the acknowledgement is not received –but what happens if an acknowledgement is lost !? –scrambled messages a message may be corrupted in the communication network include checksum information to detect this & resend –authentication an imposter may intercept the delivery of a message a solution may be some encryption with authentication keys

Software Interrupts UNIX Signals

© JMU, 2004CY2003- Week 0619 UNIX Signals A UNIX signal is similar to a software interrupt –a process may send a signal to another process –when a signal arrives, the receiving process stops what it is doing and immediately services the signal A signal is sent by using the kill system call kill(process_id, signal_number); The action taken when a signal is received by a process is specified by the signal system call –it can (usually) be ignored –it can terminate the process –it can be ‘caught’ by a special signal handling function

© JMU, 2004CY2003- Week 0620 Signal Examples SIGKILLsent to a process to immediately kill it this signal cannot be caught or ignored typically used by the system to stop processes at shutdown or by root to kill runaway processes via the ‘kill’ command SIGFPEfloating point error SIGINT/QUITtwo levels of keyboard interrupt SIGINT is ‘gentler’: interpreted as a request to stop SIGQUIT is ‘harder’: an instruction to stop

© JMU, 2004CY2003- Week 0621 Summary Recall: Semaphores theory Monitors –Solving the producer-consumer problem Message passing –Solving the producer-consumer problem Software interrupts –UNIX signals