Go backward to initmbox
Go up to Messages and Mail Boxes
Go forward to Interrupt Handling

Send and Receive

The send and receive primitives are executed by processes wishing to exchange messages. The headers for these functions are shown below:
/* Receive  -  Receive a message from 'mailbox'.  If necessary     */
/*             suspend requesting process until a message arrives. */
struct msg *receive(mailbox)
struct mbox *mailbox;


/* Send     - Send 'message' to 'mailbox'.  Enqueue the message */
/*            and awaken a waiting process if one exists.       */
send(mailbox, message)
struct mbox *mailbox;
struct msg *message;
Receive is to be implemented as a function that returns a pointer to the message received. If a message is stored in the queue of messages associated with the "mailbox" selected, the first message stored should be removed from the queue and returned. Otherwise, the calling process should be removed from the ready queue and added to the queue waiting on the mail box.

Send takes both a mail box and a message as a parameter. The new message is simply added to the queue of messages to be delivered. If processes are waiting on the mailbox, the first waiting process is removed from the queue associated with the mail box and placed in the ready queue.



Prev Up Next