CS452 - Real-Time Programming - Spring 2015

Lecture 9 - Send-Receive-Reply

Public Service Annoucements

  1. Due date for kernel 2: Thursday, 29 January, 2015
  2. 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

Overview

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 *msg, int msglen )

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

Send and Reply become READY at exactly the same time.


How are They Used?

The Producer/Consumer Problem

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

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

Producer Sends

Upper arrow

  1. producer sends and blocks (I have some stuff for you)
  2. consumer receives (Give me some stuff now)
  3. consumer accepts stuff
  4. consumer replies (I got the stuff)
  5. 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. Consumer sends and blocks (I am ready for some stuff.)
  2. Producer receives (I have some stuff now.)
  3. Producer replies (Here is the stuff)
  4. Consumer accepts stuff
  5. Producer and consumer are simultaneously READY

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

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. From producer:
  2. From Consumer:

Notes.


Sequence of States

Sender

  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 (times 2)

Receiver

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

There are two cases

Send before Receive

Sender

Action

Sender

State

Receiver

Action

Receiver

State

Comments
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

Sender

Action

Sender

State

Receiver

Action

Receiver

State

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


Practical Details


Return to: