7.4 Thread State
A thread is always in one of four states. The state of the thread is maintained in its thread data structure for use by the operating system. A good understanding of thread state is helpful in designing your application, since it leads to a better understanding of how the operating system will behave.
- Although the OS has many threads, only one thread in the system is in running state at a time. This is the thread that is currently executing on the CPU.
- A thread in runnable state is ready to run, but it is not running because some other thread has higher priority. It will gain control of the CPU once it becomes the highest-priority runnable thread.
- A stopped thread will not be scheduled for execution. Newly created threads are in this state. Threads are frequently stopped by the debugger, and an application may stop a thread at any time. Stopped threads become runnable via an osStartThread system call.
- Waiting threads are not runnable because they are waiting for some event to occur. A thread that is blocked on a message queue is in waiting state. Arrival of a message returns a waiting thread to runnable or running state.