CS452 - Real-Time Programming - Winter 2017

Lecture 9 - Send-Receive-Reply

Public Service Annoucements

  1. Due date for kernel 1: Friday, 27 May, 2017
  2. Due date for kernel 2: Monday, 30 May, 2017
  3. If you are having trouble with the values you read from or write to the pc take a look at Section 2.4.3 in the ARM Architecture Manual.

Looking ahead

Some of you may have noticed that the context switch I have described has features that are not strictly necessary for making Create work. For example

Inter-task Communication


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

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

int Receive( Tid *tid, void *message, int msglen )

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

Send and Reply become READY at exactly the same time. There is a conservation rule assciated with Send/Receive/Reply:

How are They Used?

The Producer/Consumer Problem

The middle (double) arrow shows the direction that produced stuff flows.

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

Producer Sends

Upper arrow. (We draw arrows from the sender to the receiver.)

  1. The producer sends and blocks: I have some stuff for you.
  2. The consumer receives: give me some stuff, and is given the stuff.
  3. The consumer replies: I have the stuff.
  4. The producer & consumer are simultaneously READY.

Note. 1 & 2 could run in the opposite order, in which case the consumer blocks.

Consumer Sends

Lower arrow.

  1. The consumer sends and blocks: I am ready for some stuff.
  2. The producer receives: I have some stuff now.
  3. Producer replies: here is the stuff, and the consumer accepts it.
  4. Producer and consumer are simultaneously READY.

Note. 1 & 2 could run in the opposite order, in which case the producer blocks.

Multiple Producers

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

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?

The buffer receives two types of request

  1. From the producer:
  2. From Consumer:


Sequence of States


  1. When is called
    • Sender: Active -> Receive_Blocked
    • If Receiver is not Send_Blocked, Sender goes on Receiver's SendQ.
  2. When Receiver calls Receive.
  3. Reply_Blocked -> Ready (both sender and replier)


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

There are two cases

Send before Receive









active n/a
Send RCV_BL n/a sender added to receiver's sendQ
RCV_BL active
RPL_BL Receive ready request copied
sender deleted from receiver's sendQ
RPL_BL active service performed
ready Reply ready reply copied

Receive before Send









n/a active
n/a Receive SND_BL receiver's sendQ empty
active SND_BL
Send [RCV_BL]
ready request copied
RPL_BL active service perfomed
ready Reply ready reply copied

Practical Details

Return to: