CS452 - Real-Time Programming - Spring 2012

Lecture 9 - Send/Receive/Reply

Pubilc Service Annoucements

  1. Due date for assignment 1
  2. Next week's classes
  3. Assignment 2

Inter-task Communication

Overview

Message passing combines synchronization and communication in one set of primitives.

int Send( Tid tid, char *message, int mslen, char *reply, int rplen )

int Receive( Tid *tid, char *message, int mslen )

int Reply( Tid tid, char *reply, int rplen )

Send and Reply become READY at the same time.


How are They Used?

The Producer/Consumer Problem

+--------------+          +--------------+
|              |          |              |
|   Producer   |   ===>   |   Consumer   |
|              |          |              |
+--------------+          +--------------+

Producer Sends

  1. producer sends and blocks (I have some XXX for you)
  2. consumer receives (Give me some XXX)
  3. consumer accepts XXX
  4. consumer replies (I got the XXX)
  5. producer & consumer are simultaneously READY

Note. 1 & 2 could be run in the opposite order

Consumer Sends

  1. Consumer sends and blocks (`I am ready for some XXX.')
  2. Producer receives (`I have some XXX.')
  3. Producer replies (`Here is the XXX')
  4. Consumer accepts XXX
  5. Producer and consumer are simultaneously READY

Note. 1 & 2 could be run in the opposite order

Multiple Producers

Producers send; consumer receives in the order that producers send.

Notes.

Multiple Consumers

Consumers send; producer receives in the order that consumers send.

Note. Critical races can occur, which the application programmer must resolve.

Multiple Consumers AND Multiple Producers

Consumers send and producers send: who receives?

+---------------+          +------------+          +---------------+
|               |          |            |          |               |
|   Producers   |   ===>   |   Buffer   |   ===>   |   Consumers   |
|               |          |            |          |               |
+---------------+          +------------+          +---------------+

Buffer receives two types of request

  1. Producer: Here is some XXX
    Send( ..., accept some XXX, ... )
  2. Consumer: I want some YYY
    Send( ..., want some YYY, ... )

Only a receiver can accept two types of requests at once.


Sequence of States

Sender

  1. Active -> Receive_Blocked
  2. Receive_Blocked -> Reply_Blocked
  3. Reply_Blocked -> Ready

Receiver

  1. Active -> Send_Blocked
  2. Send_Blocked -> Ready
  3. Ready -> Active
  4. ...
  5. Active -> Ready

There are two cases

Send before Receive

Send
           ...
           Receive
           ...
           Reply
...        ...

Message copying occurs inside Receive and Reply.

Receive needs to have a list of current senders, the ReceiveQ

Receive before Send

            Receive
...
Send
            ...
            Reply
...         ...

Message copying occurs inside Send and Reply.


Example of a Difficult Bug

  1. You notice that a Receiver is never on a readyQ when it is Send_Blocked
  2. You decide to use the next pointer in the TD for the head of the sendQ
  3. You test and test and test and nothing ever goes wrong
  4. One week before the demo, your kernel crashes under your application
  5. What two things might have gone wrong?

Return to: