SPONSORED LINKS

2.1.3 Threads

A thread is a single control unit of a CPU process. Under the N64 operating system, the code for all threads exists and is processed in main memory (RDRAM). A thread is like a small sub-program.

N64 game programs use of threads, messages, events, and tasks. The priority of the thread determines thread execution order.

Kinds of Threads

There are several kinds of threads. Each programmer is free to program each thread as is appropriate for a given game application. However, in most cases, a programmer creates the following kinds of threads:

State of the Thread

At any specific moment in time, a thread is in one of the following states:

Use the osStopThread function to place a thread in halt condition, and use the osStartThread function to place a thread in the ready condition.

The following illustration shows the relationships between the thread conditions:

Illustration

Keep the following facts in mind in view of the fact that all threads share RDRAM:

If you raise the optimization level by adding the -O option when you compile your code, it is possible that each thread variable won't be updated. Therefore, you have to use the volatile keyword when using a variable that is common to two threads (threads A and B for example).

Idle Thread Is Necessary

The idle thread is the lowest priority thread. This thread is executed when the CPU doesn't have any other threads to process. If this thread didn't exist, the CPU couldn't do anything. So even an idle thread has important role. Make sure your game program creates an idle thread.