Difference between revisions of "Message passing"

From Embedded Xinu
Jump to navigation Jump to search
(New page: Message passing is one method used by XINU threads for interprocess communication. It allows threads to send individual messages to other threads by using the system calls <code>send</code...)
 
(made changes to reflect the discovery that "send" is actually non-blocking)
Line 5: Line 5:
 
Threads use the functions <code>send(tid_typ tid, int msg)</code> and <code>receive(bool block)</code> to utilize this system of message passing.
 
Threads use the functions <code>send(tid_typ tid, int msg)</code> and <code>receive(bool block)</code> to utilize this system of message passing.
  
<code>send(tid_typ tid, int msg)</code> delivers the message passed in as the parameter <code>msg</code> to the message box in the thread control block of the thread with a thread id of <code>tid</code>, also passed in as a parameter. <code>send</code> is always blocking and will always reschedule if the receiving thread was in a state of waiting to receive a message (<code>THRRECV</code>).
+
<code>send(tid_typ tid, int msg)</code> delivers the message passed in as the parameter <code>msg</code> to the message box in the thread control block of the thread with a thread id of <code>tid</code>, also passed in as a parameter. <code>send</code> will always yield the processor by calling reschedule if the receiving thread was in a state of waiting to receive a message (<code>THRRECV</code>).
  
 
<code>receive(bool block)</code> returns the message waiting in the message box of the thread control block of the thread which called <code>receive</code>. If there is no message waiting for the thread then one of two things will happen depending on if the <code>receive</code> call was blocking or non-blocking. If it was blocking then the thread will go into a state of waiting to receive a message (<code>THRRECV</code>) until a message is passed to the thread. If it was non-blocking then <code>receive</code> will simply return NULL signifying that there was no message waiting for the thread.
 
<code>receive(bool block)</code> returns the message waiting in the message box of the thread control block of the thread which called <code>receive</code>. If there is no message waiting for the thread then one of two things will happen depending on if the <code>receive</code> call was blocking or non-blocking. If it was blocking then the thread will go into a state of waiting to receive a message (<code>THRRECV</code>) until a message is passed to the thread. If it was non-blocking then <code>receive</code> will simply return NULL signifying that there was no message waiting for the thread.

Revision as of 22:05, 23 June 2008

Message passing is one method used by XINU threads for interprocess communication. It allows threads to send individual messages to other threads by using the system calls send and receive. Each thread has memory allocated for a single message in its thread control block specifically for messages sent and received using this method. This form of message passing should not be confused with the mailbox messaging queue system also used for interprocess communication.

Upon creation, each thread is allocated memory in its thread control block for two fields which apply to this message passing system: a 4 byte (int type) message box to contain a single message sent to this thread, and a one byte flag (bool type) to signal if there is an unreceived message waiting in that thread's message box.

Threads use the functions send(tid_typ tid, int msg) and receive(bool block) to utilize this system of message passing.

send(tid_typ tid, int msg) delivers the message passed in as the parameter msg to the message box in the thread control block of the thread with a thread id of tid, also passed in as a parameter. send will always yield the processor by calling reschedule if the receiving thread was in a state of waiting to receive a message (THRRECV).

receive(bool block) returns the message waiting in the message box of the thread control block of the thread which called receive. If there is no message waiting for the thread then one of two things will happen depending on if the receive call was blocking or non-blocking. If it was blocking then the thread will go into a state of waiting to receive a message (THRRECV) until a message is passed to the thread. If it was non-blocking then receive will simply return NULL signifying that there was no message waiting for the thread.