1 / 15

Cooperating Processes

Cooperating Processes. Independent process cannot affect or be affected by the execution of another process. Cooperating process can affect or be affected by the execution of another process Advantages of process cooperation Information sharing Computation speed-up Modularity Convenience

Download Presentation

Cooperating Processes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Cooperating Processes • Independent process cannot affect or be affected by the execution of another process. • Cooperating process can affect or be affected by the execution of another process • Advantages of process cooperation • Information sharing • Computation speed-up • Modularity • Convenience • Robustness Operating System Concepts

  2. Producer-Consumer Problem • Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process. • unbounded-buffer places no practical limit on the size of the buffer. • bounded-buffer assumes that there is a fixed buffer size. Operating System Concepts

  3. Mechanisms for IPC Operating System Concepts

  4. Bounded-Buffer – Shared Memory Solution • Shared data #define BUFFER_SIZE 10 typedef struct { . . . } item; item buffer[BUFFER_SIZE]; int in = 0; int out = 0; Operating System Concepts

  5. Bounded-Buffer – Shared Memory Solution • Producer while (1) { while (((in + 1) % BUFFER_SIZE) == out) ; /* do nothing */ buffer[in] = nextProduced; in = (in + 1) % BUFFER_SIZE; } • Consumer while (1) { while (in == out) ; /* do nothing */ nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; • Can only use BUFFER_SIZE-1 elements Operating System Concepts

  6. Message Passing • Processes communicate without shared variables • If P and Q wish to communicate, they need to: • establish a communicationlink between them • send(message) • receive(message) • Producer - Consumer while (1) { send(consumer,produceNext()); } while (1) { nextToConsume = receive(producer); } Operating System Concepts

  7. Message Passing - Link Properties • How are links established? • Can a link be associated with more than two processes? • How many links can there be between processes? • What is the capacity of a link? (buffers?) • Fixed or variable size messages? • Is the link simplex or duplex or full duplex? Operating System Concepts

  8. Message Passing - Logical Properties • Direct or indirect communication (process or mailbox) • Symmetric or asymmetric (names both ways or one way) • Automatic or explicit or no buffering • Send by copy or send by reference • Fixed or variable size messages • Synchronous (blocking) or asynchronous (non-blocking) Operating System Concepts

  9. Symmetry of naming Operating System Concepts

  10. Direct Communication • Symmetric: Processes name each explicitly • send (P, message) – send a message to process P • receive(Q, message) – receive a message from process Q • Links are established automatically, on demand. • A link is associated with exactly two processes. • Between each pair there exists exactly one link. • Asymmetric: Only sender names the receiver • send (P, message) – send message to process P • receive(?, message) – receive message from anyone • Asymmetric: Only receiver names the sender • send (?, message) – send message to anyone (copies?) • receive(Q, message) – receive message from process Q Operating System Concepts

  11. Indirect Communication • Messages are directed and received from mailboxes (also referred to as ports). • Each mailbox has a unique id. • Processes can communicate only if they share a mailbox. • Operations • Create a new mailbox (Ownership? Who receives?) • send(A,message) – send a message to mailbox A • message = receive(A) – receive a message from A • Destroy a mailbox (? If owner terminates) • Properties of communication link • Link established only if processes share a common mailbox • A link may be associated with many processes. • Each pair of processes may share several links. Operating System Concepts

  12. Indirect Communication • Mailbox sharing • P1, P2, and P3 share mailbox A. • P1, sends; P2and P3 receive. • Who gets the message? • Solutions • Allow a link to be associated with at most two processes. • Allow only one process at a time to execute a receive • Allow the system to select arbitrarily the receiver. • Sender is notified who the receiver was. • Atomicity, regardless Operating System Concepts

  13. Synchronization • Send and receive can be blocking or non-blocking • Blocking send waits until message is received • Non-blocking send allows sender to continue • Sender is not assured of reception - must ack • Sender send(receiver,message); receive(receiver,ack_message); • Receiver receive(sender,message); send(sender,”ack”); • Blocking receive waits until message is available • Non-blocking receive returns null if no message • Blocking send and receives forces a rendezvous Operating System Concepts

  14. Buffering • Queue of messages attached to the link; implemented in one of three ways. • Zero capacity – 0 messagesSender must wait for receiver (must rendezvous). • Bounded capacity – finite length of n messagesSender must wait if link full, or overwrite • Unbounded capacity – infinite length (right!). Operating System Concepts

  15. Exception Conditions • Process terminates • Receiver waiting for a message from terminated sender • Notify or terminate receiver • Sending to a terminated receiver • Delete message • Notify sender? • Lost messages • Detect with timeouts - expect an ack within some time • Resend (duplicates) • Scrambled messages • Error checking codes Operating System Concepts

More Related