CS452 - Real-Time Programming - Winter 2013

Lecture 9 - Send/Receive/Reply

Pubilc Service Annoucements

  1. Due date for 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 *msg, int msglen )

int Reply( Tid tid, char *rply, int rplylen )

Send and Reply become READY at the same time.


How are They Used?

The Producer/Consumer Problem

Middle (double) arrow shows the direction that information flows.

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

Producer Sends

Upper arrow

  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

Lower arrow

  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( warehouse, accept some XXX, ... )
  2. Consumer: I want some YYY
    Send( warehouse, want some YYY, ... )

Notes.


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

Sender

Action

Sender

State

Receiver

Action

Receiver

State

Comments
active
Send RCV_BL sender added to receiver's sendQ
active
RPL_BL Receive ready request copied

sender deleted from receiver's sendQ

active service performed
ready Reply ready reply copied

Receive before Send

Sender

Action

Sender

State

Receiver

Action

Receiver

State

Comments
active
Receive SND_BL receiver's sendQ empty
active
Send RPL_BL ready request copied
active service perfomed
ready Reply ready reply copied


Practical Details

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

What two things might have gone wrong?

You might have caught one while testing, not likely the other.


Return to: