Operating System Concepts and Techniques Lecture 14 Interprocess communication-3 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and.

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.
Operating Systems Lecture 7.
Ch 7 B.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Operating System Concepts and Techniques Lecture 12 Interprocess communication-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and.
©2009 Operačné systémy Procesy. 3.2 ©2009 Operačné systémy Process in Memory.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles Seventh Edition By William Stallings.
Intertask Communication and Synchronization In this context, the terms “task” and “process” are used interchangeably.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
CY2003 Computer Systems Lecture 05 Semaphores - Theory.
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, Semaphores. Four different approaches Hardware support Disable interrupts Special instructions Software-defined approaches.
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 2: Processes Topics –Processes –Threads –Process Scheduling –Inter Process Communication (IPC) Reference: Operating Systems Design and Implementation.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
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.
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: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
Chapter 2.3 : Interprocess Communication
Semaphores CSCI 444/544 Operating Systems Fall 2008.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
Semaphores Questions answered in this lecture: Why are semaphores necessary? How are semaphores used for mutual exclusion? How are semaphores used for.
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.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Semaphores and Bounded Buffer Andy Wang Operating Systems COP 4610 / CGS 5765.
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.
CY2003 Computer Systems Lecture 06 Interprocess Communication Monitors.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago.
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.
Chapter 1 Computer System Overview Sections 1.1 to 1.6 Instruction exe cution Interrupt Memory hierarchy Cache memory Locality: spatial and temporal Problem.
3.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Interprocess Communication Processes within a system may be.
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.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-4 Process Communication Department of Computer Science and Software.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 10 Processes II Read.
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
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.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 24 Critical Regions.
Lecture 6: Monitors & Semaphores. Monitor Contains data and procedures needed to allocate shared resources Accessible only within the monitor No way for.
Stacey Levine Chapter 4.1 Message Passing Communication.
Processes. Process Concept Process Scheduling Operations on Processes Interprocess Communication Communication in Client-Server Systems.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Previous Lecture Overview  semaphores provide the first high-level synchronization abstraction that is possible to implement efficiently in OS. This.
Operating Systems COMP 4850/CISG 5550 Interprocess Communication, Part II Dr. James Money.
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.
Operating System Concepts and Techniques Lecture 13 Interprocess communication-2 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and.
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process Termination Process executes last statement and asks the operating.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Mutual Exclusion Mutexes, Semaphores.
© 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
CS703 - Advanced Operating Systems
Chapter 5 Concurrency: Mutual Exclusion and Synchronization
CIS Operating Systems Synchronization
Concurrency: Mutual Exclusion and Synchronization
Chapter 5: Process Synchronization
Chapter 6 Synchronization Principles
CSE 153 Design of Operating Systems Winter 19
Presentation transcript:

Operating System Concepts and Techniques Lecture 14 Interprocess communication-3 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, irst ed., iUniverse Inc., To order: or

Main program to spawn producer and consumer processes void main (void) { int pid; pid = fork(); if (pid != 0) producer(); else consumer(); } 2

Semaphore adv/disadv Advantages A general solution for binary and integer constraints No busy-wait; if a process wants to use an unavailable resource it sleeps in the queue of waiting processes for that resource Disadvantages Somewhat difficult to use, but remember, OS designers are highly skilled 3

Dijkstra’s P and V Dijkstra first implemented down and up methods as follows P(s) s = s-1; if s < 0 wait (s); V(s) s = s+1; if s ≤ 0 signal(s); It is simple, symmetric, and it knows how many processes are waiting for the resource With down and up we do not know how many processes are waiting for the resource 4

Monitor Based IPC Monitor concept is for simplifying the implementation of ME Primitives are: Wait Signal On condition variables wait and signal may be executed Only one process could be inside monitor at any time  ME 5

Sample monitor class insert_remove : public monitor { private: condition available, occupied; int count; public: insert (struct buffer_slot &entity); { if (count == BC) wait (&available); insert_entity(&entity); count = count +1; if (count ==1) signal(&occupied) } remove (struct buffer_slot &entity) { if (count == 0) wait (&cooupied); remove_entity(&entity); count = count - 1; if (count = BC-1) signal(&available); } Insert_remove (condition available=BC, condition occupied=0, int count=0); } insert_remove IR; 6

Producer-Consumer class producer_consumer { private: struct buffer_slot entity; public: producer() { while (true) { produce_entity (&entity); IR.insert (&entity) ; } } consumer() { while (true) { IR.remove(&entity); consume_entity(&entity); } } producer_consumer (struct buffer_slot entity =””); } 7

Message-Based IPC method Message is mainly used for information interchange between in distributed systems, however, it can be used within standalone computers There are two main system calls, send and receive; usually with the following format send (source, destination, message) receive (source, destination, message) 8

Blocking/Non-blocking Sending/receiving could be blocking or non-blocking; we are interested in non-blocking send and blocking receive Blocking send: The execution of the sender process is suspended until the message is delivered and the receiver informs the sender of the matter Nonblocking send: The sender executes the send and continues its execution; The sender will not become aware of whether or not the message was actually delivered Blocking receive: The receiver(s) executes a receive and waits until the message is fully received before proceeding Non-blocking receive: The receiver executes a receive and continues its execution; if the message is available it is received, otherwise, when the message is received the kernel will send an interrupt to the corresponding receiver process informing it of the receipt of message 9

How to enforce mutual exclusion Suppose we have a common mailbox with one message in it Whichever process grabs the message is allowed to use the critical resource After the execution of its critical section, the process sends back the message to the mailbox Proper send and receive statements for this purpose would be: receive (mailbox, message) send (mailbox, message) 10

The producer procedure The following is the initialization and the producer #define true 1 #define BC 1000 // Buffer capacity void producer (void) { struct buffer_slot entity; message msg1, msg2; while (true) { produce_an_entity(&entity); receive (consumer, producer, &msg1); //Wait for consumer’s message receive (mailbox,&msg2); //Get permission to use the entity-queue insert_the_entity(&entity); //Put entity in queue send (mailbox, &msg2); //Free the resource, i.e., queue send (producer, consumer,&msg1);//One slot is filled } 11

The consumer procedure void consumer (void) { struct buffer_slot entity; message msg1, msg2; for (i=0; i<BC; i++) send (consumer, producer, &msg1); //BC slots are free while (true) { receive (producer, consumer, &msg1);//Wait until there is an entity receive (mailbox, &msg2); remove_the_entity(&entity); send (maibox, msg2); send (consumer, producer,msg1); consume_the_entity(&entity); } 12

Main program to spawn producer and consumer processes void main (void) { int pid; message msg2; send (mailbox, &msg2); pid = fork(); if (pid != 0) producer(); else consumer(); } 13

Summary The semaphore method does not suffer from busy- wait; it is not restricted to two processes; it can be used in multiprocessor environments. The message-based method is borrowed from distributed operating systems, but it works on centralized systems, as well Depending on the types of send and receive, there are four possible combinations Non-blocking send and blocking receive fits our need to solve problems like producer-consumer In message passing solutions, message loss could pose a problem 14

15 Find out Whether a process can wake itself up after sleeping due to the execution of wait(&s) If it is logical to execute wait (&mutex) before wait (&available) in the producer-consumer problem The correspondence between P and V on to down and up, respectively How can we modify down and up to count the number of processes sleeping in the queue of a resource What would happen if we used non-blocking receive for the implementation of producer consumer

16 Any questions?