Presentation is loading. Please wait.

Presentation is loading. Please wait.

Silberschatz, Galvin and Gagne  2002 4.1 Operating System Concepts Cooperating Processes Independent process cannot affect or be affected by the execution.

Similar presentations


Presentation on theme: "Silberschatz, Galvin and Gagne  2002 4.1 Operating System Concepts Cooperating Processes Independent process cannot affect or be affected by the execution."— Presentation transcript:

1 Silberschatz, Galvin and Gagne  2002 4.1 Operating System Concepts 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

2 Silberschatz, Galvin and Gagne  2002 4.2 Operating System Concepts 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.

3 Silberschatz, Galvin and Gagne  2002 4.3 Operating System Concepts Mechanisms for IPC

4 Silberschatz, Galvin and Gagne  2002 4.4 Operating System Concepts Bounded-Buffer – Shared Memory Solution Shared data #define BUFFER_SIZE 10 typedef struct {... } item; item buffer[BUFFER_SIZE]; int in = 0; int out = 0;

5 Silberschatz, Galvin and Gagne  2002 4.5 Operating System Concepts 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 Bounded-Buffer – Shared Memory Solution

6 Silberschatz, Galvin and Gagne  2002 4.6 Operating System Concepts Message Passing Processes communicate without shared variables If P and Q wish to communicate, they need to:  establish a communication link between them  send(message)  receive(message) Producer - Consumer while (1) { send(consumer,produceNext()); } while (1) { nextToConsume = receive(producer); }

7 Silberschatz, Galvin and Gagne  2002 4.7 Operating System Concepts 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?

8 Silberschatz, Galvin and Gagne  2002 4.8 Operating System Concepts 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)

9 Silberschatz, Galvin and Gagne  2002 4.9 Operating System Concepts Symmetry of naming

10 Silberschatz, Galvin and Gagne  2002 4.10 Operating System Concepts 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

11 Silberschatz, Galvin and Gagne  2002 4.11 Operating System Concepts 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.

12 Silberschatz, Galvin and Gagne  2002 4.12 Operating System Concepts Indirect Communication Mailbox sharing  P 1, P 2, and P 3 share mailbox A.  P 1, sends; P 2 and P 3 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

13 Silberschatz, Galvin and Gagne  2002 4.13 Operating System Concepts 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

14 Silberschatz, Galvin and Gagne  2002 4.14 Operating System Concepts Buffering Queue of messages attached to the link; implemented in one of three ways. o Zero capacity – 0 messages Sender must wait for receiver (must rendezvous). o Bounded capacity – finite length of n messages Sender must wait if link full, or overwrite o Unbounded capacity – infinite length (right!).

15 Silberschatz, Galvin and Gagne  2002 4.15 Operating System Concepts 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


Download ppt "Silberschatz, Galvin and Gagne  2002 4.1 Operating System Concepts Cooperating Processes Independent process cannot affect or be affected by the execution."

Similar presentations


Ads by Google