Synchronization Methods in Message Passing Model.

Slides:



Advertisements
Similar presentations
Processes Management.
Advertisements

IPC (Interprocess Communication)
Operating Systems Lecture 7.
COMMUNICATING SEQUENTIAL PROCESSES C. A. R. Hoare The Queen’s University Belfast, North Ireland.
Ch4. Processes Process Concept (1) new waiting terminate readyrunning admitted interrupt exit scheduler dispatch I/O or event completion.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
©2009 Operačné systémy Procesy. 3.2 ©2009 Operačné systémy Process in Memory.
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.
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.
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
1/30/2004CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
02/02/2004CSCI 315 Operating Systems Design1 Interprocesses Communication Notice: The slides for this lecture have been largely based on those accompanying.
Asynchronous Message Passing EE 524/CS 561 Wanliang Ma 03/08/2000.
02/01/2010CSCI 315 Operating Systems Design1 Interprocess Communication Notice: The slides for this lecture have been largely based on those accompanying.
1/26/2007CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Concurrency - 1 Tasking Concurrent Programming Declaration, creation, activation, termination Synchronization and communication Time and delays conditional.
Interprocess Communication. Process Concepts Last class.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings 1.
Message passing model. buffer producerconsumer PRODUCER-CONSUMER PROBLEM.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication in Client-Server.
Silberschatz, Galvin and Gagne  Operating System Concepts Cooperating Processes Independent process cannot affect or be affected by the execution.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Process Concept Process – a program.
1 Concurrency Architecture Types Tasks Synchronization –Semaphores –Monitors –Message Passing Concurrency in Ada Java Threads.
1 Lecture 5 (part2) : “Interprocess communication” n reasons for process cooperation n types of message passing n direct and indirect message passing n.
Producer-Consumer Problem The problem describes two processes, the producer and the consumer, who share a common, fixed-size buffer used as a queue.bufferqueue.
3.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Interprocess Communication Processes within a system may be.
Processes. Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication.
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.
ICS 313: Programming Language Theory Chapter 13: Concurrency.
Semantics of Send and Receive Can be blocking or nonblocking –called “synchronous” and “asynchronous” –remember: procedure call is synchronous thread fork.
Processes CSCI 4534 Chapter 4. Introduction Early computer systems allowed one program to be executed at a time –The program had complete control of the.
Chapter 3 Process Scheduling Bernard Chen Spring 2007.
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.
PREPARED BY : MAZHAR JAVED AWAN BSCS-III Process Communication & Threads 4 December 2015.
Chapter 3: Process-Concept. Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication.
Distributed Programming Concepts and Notations. Inter-process Communication Synchronous Messages Asynchronous Messages Select statement Remote procedure.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
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.
 Process Concept  Process Scheduling  Operations on Processes  Cooperating Processes  Interprocess Communication  Communication in Client-Server.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process Termination Process executes last statement and asks the operating.
Channels. Models for Communications Synchronous communications – E.g. Telephone call Asynchronous communications – E.g. .
CSC 360, Instructor: Kui Wu IPC. CSC 360, Instructor: Kui Wu Agenda 1.The need to communicate 2.Shared memory 3.Message passing.
Message passing model. buffer producerconsumer PRODUCER-CONSUMER PROBLEM.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Chapter 3: Process Concept
Concurrency: Mutual Exclusion and Synchronization
Chapter 4: Processes Process Concept Process Scheduling
Condition Variables and Producer/Consumer
Inter Process Communication (IPC)
Condition Variables and Producer/Consumer
Operating System Concepts
Channels.
Typically for using the shared memory the processes should:
Process Synchronization
Channels.
Outline Chapter 2 (cont) Chapter 3: Processes Virtual machines
Chapter 3: Process Concept
Presentation transcript:

Synchronization Methods in Message Passing Model

Message Passing Model  Channel Specification  Specify how to communicate  Synchronization Mechanisms  The synchronization mechanism between sender and receiver  Block/nonblock send, block/nonblock receive  Guarded communication

Channel Specification  Direct naming  Simple but less powerful  Not suitable for specification of server-client systems  Port naming  Server use a single port to receive client request  Simple, suitable for single server, multiple client systems  Global naming (mailbox)  Suitable for multiple server, multiple client systems  Hard to implement for multiple processor systems  When a message is received or removed, all servers should be notified

Synchronization  Blocked send, blocked receive (BSBR)  Easy to implement but less powerful  Example: Ada Rendezvous  Nonblocked send, blocked receive (NSBR)  Most message passing systems use this model  need unbounded message queue to assure correctness  Nonblocked send, nonblocked receive (NSNR)  More powerful than NSBR and BSBR  But difficult to reason the correctness of the system  The state of the system can be very different at the time the message is received

Producers-Consumer Problem  Consider multiple producers and multiple consumers  Any producer’s output can be processed by any consumer  Use port naming  Each process has a port  Won’t work since each producer needs to decide which consumer the produced item should be sent to  Not conform to the spec  Use a buffer manager  Assume only port naming is available  The manager manage a shared buffer  Similar to mailbox, but user implements shared box

Producers-Consumer Problem  Solution based on buffer manager and port naming  How to synchronize the producers and consumers with the bounded buffer  Buffer full  Stop receiving messages from producers  Buffer empty  Stop receiving messages from consumers   Need blocked send to achieve the control   Manager needs two ports, one for consumers, one for producers  Otherwise, cannot block only consumers or only producers  Still have problem: How to read from two ports  Solution 1: Use blocked receive and two threads  Manager cannot do blocked receive on both ports  Solution 2: Use nonblocked receive  Poll two ports using BSNR

Producer-Consumer Problem  Manager process (P mamnager )  reqport: manager receives requests from consumers  dataport: manager receives data items from producers  BSNR  Receive returns immediately, it returns true if a message is ready in the port, otherwise, false  Send only returns after the message is received  count: # data items in P mamnager ’s buffer

Producer-Consumer Problem Producer Process: repeat produce item; send (dataport, item); until false; Consumer Process: repeat send (reqport, localport); while not receive (localport, item) do nothing; consume item; until false;

Producer-Consumer Problem Manager Process: repeat forever if count = 0 then { while not receive (dataport, item) do nothing; put item in the queue; count := count + 1; } else if count = N then { while notreceive (reqport, port) do nothing; take item from queue; count := count - 1; send (port, item); } else { if receive (dataport, item) then { put item in the queue; count := count + 1; } if receive (reqport, port) then { take item from queue; count := count - 1; send (port, item); }

Guarded Command  Guarded command  Guarded statement: G  S  When the guard G is true, execute statement S  Guarded command in CSP if G 1  S 1 || G 2  S 2 ||... || G n  S n fi  When G i is true, execute S i  If more than one guard is true, then choose one of them arbitrarily and execute the corresponding statement  If none of the guards are true, then terminate the statement without doing anything

Guarded Communication  Guarded communication:  Statements in a guarded command contain message passing operations  Message passing is based on BSBR  A guarded communication statement is ready when  The guard is true  For receive statement: The message to be received is ready  For send statement: The receiver of the message is ready  If none of the guards are true, then terminate the statement  If some guards are true and no message is ready then blocked

Producer-Consumer Problem Manager Process: repeat select when count < N { receive (dataport, item); -- from producer put item in the queue; count := count + 1; } when count > 0 { receive (reqport, port); -- from consumer take item from queue; send (port, item); count := count - 1; } until false;

Guarded Communication  Guarded communication in Ada: select when G1 => accept P1 do.... end; when G2 => accept P2 do.... end; ….. else....; end select  Now guarded communication is adopted in socket  Gradually being adopted for server implementation  Better performance than thread based implementation