CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 1 More on Synchronization Interprocess Communication (IPC) CS-3013 & CS-502 Summer 2006.

Slides:



Advertisements
Similar presentations
Operating Systems Lecture 7.
Advertisements

Ch 7 B.
©2009 Operačné systémy Procesy. 3.2 ©2009 Operačné systémy Process in Memory.
 2004 Deitel & Associates, Inc. All rights reserved. 1 Chapter 3 – Process Concepts Outline 3.1 Introduction 3.1.1Definition of Process 3.2Process States:
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
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.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Operating System Inter-Process Communication. IPC F How does one process communicate with another process? –semaphores -- signal notifies waiting process.
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.
Operating Systems Process Synchronization (Ch 2.3, 2.4)
Synchronization and IPC 1 CS502 Spring 2006 More on Synchronization Interprocess Communication (IPC) CS-502 Spring 2006.
Synchronization: Monitors Hank Levy. 6/21/20152 Synchronization with Semaphores Semaphores can be used to solve any of the traditional synchronization.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
3.5 Interprocess Communication
Inter-process Communication CS-502 Fall Interprocess Communication (IPC) CS-502 Operating Systems Fall 2006 (Slides include materials from Operating.
Monitors CSCI 444/544 Operating Systems Fall 2008.
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.
CS444/CS544 Operating Systems Classic Synchronization Problems 2/26/2007 Prof. Searleman
Operating Systems Process Synchronization (Ch )
1/26/2007CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
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.
Operating Systems Process Synchronization (Ch , )
Experience with Processes and Monitors in Mesa
Inter-Process Communication Mechanisms CSE331 Operating Systems Design.
1 CS 333 Introduction to Operating Systems Class 6 – Monitors and Message Passing Jonathan Walpole Computer Science Portland State University.
© 2004, D. J. Foreman 1 High Level Synchronization and Inter-Process Communication.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
CY2003 Computer Systems Lecture 06 Interprocess Communication Monitors.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Processes. Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
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.
CE Operating Systems Lecture 13 Linux/Unix interprocess communication.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-4 Process Communication Department of Computer Science and Software.
PREPARED BY : MAZHAR JAVED AWAN BSCS-III Process Communication & Threads 4 December 2015.
Operating Systems Yasir Kiani. 13-Sep Agenda for Today Review of previous lecture Interprocess communication (IPC) and process synchronization UNIX/Linux.
Washington WASHINGTON UNIVERSITY IN ST LOUIS Core Inter-Process Communication Mechanisms (Historically Important) Fred Kuhns
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 24 Critical Regions.
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
IT 344: Operating Systems Winter 2008 Module 7 Semaphores and Monitors
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.
Chapter 71 Monitors (7.7)  A high-level-language object-oriented concept that attempts to simplify the programming of synchronization problems  A synchronization.
1 Advanced Operating Systems - Fall 2009 Lecture 7 – February 2, 2009 Dan C. Marinescu Office: HEC 439 B. Office hours:
© 2004, D. J. Foreman 1 Monitors and Inter-Process Communication.
© 2004, D. J. Foreman 1 Monitors and Inter-Process Communication.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
CIS Operating Systems Synchronization
Protection of System Resources
Chapter 3 – Process Concepts
Interprocess Communication (IPC)
Concurrency: Mutual Exclusion and Synchronization
Inter-Process Communication
Operating Systems Lecture 8.
Chapter 7: Synchronization Examples
CSE 451: Operating Systems Winter 2004 Module 7+ Monitor Supplement
CSE 451: Operating Systems Autumn Lecture 8 Semaphores and Monitors
CSE 451: Operating Systems Autumn Lecture 7 Semaphores and Monitors
CSE 451: Operating Systems Winter Module 7 Semaphores and Monitors
Synchronization: Monitors
CSE 153 Design of Operating Systems Winter 2019
Monitors and Inter-Process Communication
Process Synchronization (Ch , )
Presentation transcript:

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 1 More on Synchronization Interprocess Communication (IPC) CS-3013 & CS-502 Summer 2006

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 2 Interprocess Communication Wide Variety of interprocess communication (IPC) mechanisms – e.g., Pipes & streams Sockets & Messages Remote Procedure Call Shared memory –OS dependent Depends on whether the communicating processes share all or part of an address space

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 3 Interprocess Communication Common IPC mechanisms –shared memory – read/write to shared region E.g., shmget(), shmctl() in Unix Memory mapped files in WinNT/2000 Need critical section management –semaphores – post_s() notifies waiting process Shared memory or not –software interrupts - process notified asynchronously signal () –pipes - unidirectional stream communication –message passing - processes send and receive messages Across address spaces

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 4 IPC – Software Interrupts Similar to hardware interrupt. –Processes interrupt each other –Non-process activities interrupt processes Asynchronous! Stops execution then restarts –Keyboard driven – e.g. cntl-C –An alarm scheduled by the process expires Unix: SIGALRM from alarm() or settimer() –resource limit exceeded (disk quota, CPU time...) –programming errors: invalid data, divide by zero

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 5 Software Interrupts (continued) SendInterrupt(pid, num) –Send signal type num to process pid, –kill() in Unix –(NT doesn’t allow signals to processes) HandleInterrupt(num, handler) –type num, use function handler –signal() in Unix –Use exception handler in WinNT/2000 Typical handlers: –ignore –terminate (maybe w/core dump) –user-defined

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 6 Software Interrupts (continued) Will need to use software interrupts for Programming Project #3 (Web Server) –For cleanly exiting the server

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 7 IPC – Pipes A pipe is a unidirectional stream connection between 2 processes –Unix/Linux 2 file descriptors Byte stream –Win/NT 1 handle Byte stream and structured (messages)

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 8 IPC – Pipes #include #include <unistd.h #include #define BUFFSIZE 1024 char data[ ] = “whatever” int pipefd[2]; /* file descriptors for pipe ends */ /* NO ERROR CHECKING, ILLUSTRATION ONLY!!!!! */ main() { char sbBuf[BUFFSIZE]; pipe(pipefd); if (fork() > 0 ) { /* parent, read from pipe */ close(pipefd[1]); /* close write end */ read(pipefd[0], sbBuf, BUFFSIZE); /* do something with the data */ } else { /* child, write data to pipe */ close(pipefd[0]); /* close read end */ write(pipefd[1], data, sizeof(DATA)); close(pipefd[1]); exit(0); }

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 9 IPC – Message Passing Communicate information from one process to another via primitives: send(dest, &message) receive(source, &message) Receiver can specify ANY Receiver can choose to block or not Applicable to multiprocessor and distributed systems

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 10 IPC – Message Passing void Producer() { while (TRUE) { /* produce item */ build_message(&m, item); send(consumer, &m); /* send message */ receive(consumer, &m); /* wait for ack */ } void Consumer { while(TRUE) { receive(producer, &m); /* receive message */ extract_item(&m, &item); send(producer, &m); /* send ack */ /* consume item */ }

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 11 IPC – Message Passing –send ( ) operation Synchronous –Returns after data is sent –Blocks if buffer is full Asynchronous –Returns as soon as I/O started –Done? »Explicit check »Signal –Blocks if buffer is full –receive () operation Sync. –Returns if there is a message –Blocks if not Async. –Returns if there is a message –Returns indication if no message

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 12 IPC – Message Passing Indirect Communication – mailboxes –Messages are sent to a named area – mailbox –Processes read messages from the mailbox –Mailbox must be created and managed –Sender blocks if mailbox is full –Enables many-to-many communication

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 13 Message Passing issues Scrambled messages (checksum) Lost messages (acknowledgements) Lost acknowledgements (sequence no.) Process unreachable (down, terminates) Naming Authentication Performance (copying, message building)

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 14 Beyond Semaphores Semaphores can help solve many traditional synchronization problems, BUT: –Have no direct relationship to the data being controlled –Difficult to use correctly; easily misused Global variables Proper usage requires superhuman attention to detail Another approach – use programming language support

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 15 Monitors Programming language construct that supports controlled access to shared data –Compiler adds synchronization automatically –Enforced at runtime Encapsulates –Shared data structures –Procedures/functions that operate on the data –Synchronization between processes calling those procedures Only one process active inside a monitor at any instant –All procedures are part of critical section Hoare, C.A.R., “Monitors: An Operating System Structuring Concept,” Communications of ACM, vol. 17, pp , Oct (.pdf).pdf

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 16 Monitors High-level synchronization allowing safe sharing of an abstract data type among concurrent processes. monitor monitor-name { shared variable declarations procedure body P1 (…) {... } procedure body P2 (…) {... } procedure body Pn (…) {... } { initialization code }

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 17 Monitors shared data operations (procedures) at most one process in monitor at a time

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 18 Monitors Mutual exclusion –only one process can be executing inside at any time –if a second process tries to enter a monitor procedure, it blocks until the first has left the monitor Once inside a monitor, process may discover it is not able to continue condition variables provided within monitor processes can wait or signal others to continue condition variable can only be accessed from inside monitor wait’ing process relinquishes monitor temporarily

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 19 Monitors To allow a process to wait within the monitor, a condition variable must be declared, as condition x, y; Condition variable can only be used with the operations wait and signal. –The operation wait(x); means that the process invoking this operation is suspended until another process invokes signal(x); –The signal operation resumes exactly one suspended process. If no process is suspended, then the signal operation has no effect.

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 20 wait and signal (continued) When process invokes wait, it reliquishes the monitor lock to allow other processes in. When process invokes signal, the resumed process must reacquire monitor lock before it can proceed (inside the monitor)

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 21 Monitors – Condition Variables

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 22 Monitors monitor ProducerConsumer { condition full, empty; integer count = 0; /* function prototypes */ void insert(item i); item remove(); } void producer(); void consumer(); void producer() { item i; while (TRUE) { /* produce item i */ ProducerConsumer.insert(i); } void consumer() { item i; while (TRUE) { i = ProducerConsumer.remove(); /* consume item i */ }

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 23 Monitors void insert (item i) { if (count == N) wait(full); /* add item i */ count = count + 1; if (count == 1) then signal(empty); } item remove () { if (count == 0) wait(empty); /* remove item into i */ count = count - 1; if (count == N-1) signal(full); return i; }

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 24 Monitors – variations Hoare monitors: signal(c) means –run waiter immediately (and acquires monitor lock) –signaler blocks immediately (and releases lock) condition guaranteed to hold when waiter runs Mesa/Pilot monitors: signal(c) means –waiter is made ready, but signaler continues waiter competes for monitor lock when signaler leaves monitor (or waits) condition is not necessarily true when waiter runs again –being woken up is only a hint that something has changed must recheck conditional case

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 25 Monitors (Mesa) void insert (item i) { while (count == N) wait(full); /* add item i */ count = count + 1; if (count == 1) then signal(empty); } item remove () { while (count == 0) wait(empty); /* remove item into i */ count = count - 1; if (count == N-1) signal(full); return i; }

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 26 Synchronization Semaphores –Easy to add to any language –Much harder to use correctly Monitors –Easier to use and to get it right –Must have language support See Lampson, B.W., and Redell, D. D., “Experience with Processes and Monitors in Mesa,” Communications of ACM, vol. 23, pp , Feb (.pdf).pdf Redell, D. D. et al. “Pilot: An Operating System for a Personal Computer,” Communications of ACM, vol. 23, pp , Feb (.pdf).pdf

CS 3013 & CS 502 Summer 2006 IPC, Synchronization, and Monitors 27 Break (next topic)