7.6 Thread Functions

There are eight functions associated with threads. Please refer to the reference pages for specifics about the arguments, return values, and behavior of these functions.

osCreateThread
This function is called once per thread to notify the system that a thread is to be created. Calling this function initializes its thread data structure with the starting program counter, initial stack pointer, and other information. When the initialization of TCB (Thread Control Block) is completed, the state of the thread becomes waiting. Furthermore, it is necessary to call osStartThread to make the thread runnable.
osDestroyThread
This function removes a thread from the system. Once called, the thread cannot be run any more.
osYieldThread
This function notifies the operating system that the running thread wishes to yield the CPU to any other thread with higher or equal priority. If all other runnable threads have lower priority, the running thread will continue. (In practice, it is not possible for a runnable thread to have higher priority than the running thread.)
osStartThread
This function call makes a thread runnable. If the specified thread is of higher priority than the running thread, the running thread will yield the CPU. If not, the running thread will continue and the thread specified by osStartThread function will wait until it becomes the highest priority thread in the system. (Note that it is different from the waiting state.)
osStopThread
This function changes the state of a thread to stopped, after which the thread will not be able to run until osStartThread function is called again. If the thread waiting on a message queue is stopped, it will be removed from that queue.
osGetThreadId
This function returns the ID of a thread assigned when the thread was created. It is used only by the debugger.
osSetThreadPri
This function changes the priority of a thread. If the running thread is no longer the highest-priority runnable thread in the system as a result of this change, it will yield the CPU to the new highest-priority thread.
osGetThreadPri
This function returns the running thread's priority level.

UP