Cooperating Processes - PowerPoint PPT Presentation

About This Presentation
Title:

Cooperating Processes

Description:

Advantages of process cooperation. Information sharing. Computation speed-up. Modularity ... Allow only one process at a time to execute a receive ... – PowerPoint PPT presentation

Number of Views:69
Avg rating:3.0/5.0
Slides: 16
Provided by: marily295
Learn more at: https://www.cs.miami.edu
Category:

less

Transcript and Presenter's Notes

Title: Cooperating Processes


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

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.

3
Mechanisms for IPC
4
Bounded-Buffer Shared Memory Solution
  • Shared data
  • define BUFFER_SIZE 10
  • typedef struct
  • . . .
  • item
  • item bufferBUFFER_SIZE
  • int in 0
  • int out 0

5
Bounded-Buffer Shared Memory Solution
  • Producer
  • while (1)
  • while (((in 1) BUFFER_SIZE) out)
  • / do nothing /
  • bufferin nextProduced
  • in (in 1) BUFFER_SIZE
  • Consumer
  • while (1)
  • while (in out)
  • / do nothing /
  • nextConsumed bufferout
  • out (out 1) BUFFER_SIZE
  • Can only use BUFFER_SIZE-1 elements

6
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
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
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
Symmetry of naming
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

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.

12
Indirect Communication
  • Mailbox sharing
  • P1, P2, and P3 share mailbox A.
  • P1, sends P2 and 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

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

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!).

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
Write a Comment
User Comments (0)
About PowerShow.com