1-4 Messages


Threads send and receive messages to transfer information, to ensure synchronization, or to control thread execution and processor sharing. Messages are used to transfer control of the processor to higher priority threads. To do this, a message is sent that switches the state of the higher priority thread to the execution state, and a message is sent that switches the state of the currently running, lower-priority thread to the ready condition. Messages are also sent to and received by threads to synchronize processes. There are many ways to use messages. Their use is limited only by the imagination of the game developer.


1-4-1 Typical Kinds of Messages


  1. Messages issued from other threads:

  2. Messages issued for internal thread use:

  3. Messages issued from the system event:

  4. Messages issued from the system event to the Scheduler thread and then reissued to the thread:

Whereas a typical C program might provide these kinds of processes during an interruption, in the N64, the N64 operating system takes care of them by sending messages.



1-4-2 Methods for Sending and Receiving Messages


As the send/receive message has some methods, the usage depends on the application system design.


Figure 1-4-1 Messages are used to ensure thread synchronization and communication


  1. Sending Method


  2. Receiving Method


1-4-3 Notes Regarding Sending & Receiving Messages


Thread execution order depends on thread priority and the message sending method. Therefore you need to be careful to handle priority differences between a sending thread and a receiving thread. If Thread B, executing a process, sends a message to Thread A which has a higher priority than Thread B, processing moves to Thread A, and Thread B is suspended until Thread A processing has completed. However, for this to work, Thread A must be in the "queued state" waiting for the message from Thread B so that processing can instantly move to Thread A as soon as it gets the message.


Figure 1-4-2 Thread priority and message sending (high->low)


Also, be particularly careful when a high-priority Thread A sends a message to a lower-priority Thread B to get a result that Thread A needs to continue its process. If Thread A monopolizes the process, Thread B will not be able to run anything.


Figure 1-4-3 Thread priority and message sending (high->low)


To switch from one thread to another, always have the current thread yield the CPU by entering the "queued state" to wait for a reply. Then execution can move to another thread.