CS452 - Real-Time Programming - Fall 2009

Lecture 10 - Implementing Message Passing

Reminders


Message Passing

Practical Details


int Send( Tid tid, char *arg, int arg-length, char *reply-buffer, int reply-buffer-size )

These are pretty self explanatory, except

  1. The return value is the number of characters actually placed in the reply-buffer
  2. If something goes wrong, the return value is negative, coded to indicate what went wrong

    What can go wrong

    1. Illegal tid
    2. tid not an existing task

    It's up to Send to check that the reply-buffer was big enough by looking at its return value

    It's not an error if the task to which we Send never Receives

  3. Parsing argument and reply-buffer is potentially costly and error-prone

Implementing Send

What's in application space is just stubs.

What the kernel must do

  1. Check arguments
  2. Change state of sender to RECEIVE_BLOCKED
  3. Put sender on the end of the receiver's sendQ
  4. If receiver is SEND_BLOCKED, do 3 in receiver

int Receive( Tid *tid, char *arg-buffer, int arg-buffer-length )

These are pretty self explanatory, except

  1. How is the task id copied form kernel to receiver?
  2. What if the buffer wasn't big enough?
  3. If several tasks have done Send, which one gets Received first?
  4. return value is number of bytes in message, including \0.
  5. If something goes wrong, the return value is negative, coded to indicate what went wrong

    What can go wrong?

    1. Only part of the message was copied

    It's up to Send to check that the reply-buffer was big enough by looking at its return value

Implementing Receive

What the kernel must do

  1. Check arguments
  2. Change receiver's state to SEND_BLOCKED
  3. Check the sendQ
  4. If SENDQ_EMPTY
    1. Exit from kernel after scheduling
  5. sendQ is not empty
    1. sender = head( sendQ )

      sendQ = next( sendQ )

    2. copy message from sender to receiver, after checking buffer sizes
    3. change sender's state to REPLY_BLOCKED
    4. change receiver's state to READY
    5. put sender's tid into receiver's argument
    6. put receiver on its readyQ
    7. set up receiver's return value

int Reply( Tid tid, char *reply, int reply-length )

These are pretty self explanatory, except

  1. The Replyer need not be the Receiver, but must be in contact with the Receiver
  2. When all goes well Reply leaves two tasks READY when it completes

Implementing Reply

  1. Check arguments
  2. Copy message from replier to sender, checking buffer sizes
  3. Put sender on readyQ
  4. Set up sender's return value
  5. Change sender's state to READY
  6. Put replier on readyQ
  7. Set up replier's return value
  8. Change replier's state to READY

Return to: