Kernel states, the complete list
Here's the complete list of kernel blocking states, with brief explanations of each state.
By the way, this list is available in <sys/states.h>—you'll
notice that the states are all prefixed with STATE_, but the prefix tends to be omitted in
conversation and the documentation (for example, READY
is really STATE_READY):
If the state is: | The thread is: |
---|---|
STATE_BARRIER | Blocked on a barrier (e.g., after calling pthread_barrier_wait()). |
STATE_CONDVAR | Waiting for a condition variable to be signaled |
STATE_DEAD | Dead. Kernel is waiting to release the thread's resources |
STATE_INTR | Waiting for an interrupt |
STATE_JOIN | Waiting for the completion of another thread |
STATE_MQ_RECEIVE | Waiting on an empty queue after calling mq_receive(). |
STATE_MQ_SEND | Waiting on a full queue after calling mq_send(). |
STATE_MUON_MUTEX | Blocked on an internal kernel mutex |
STATE_MUTEX | Waiting to acquire a mutex |
STATE_NANOSLEEP | Sleeping for a period of time |
STATE_READY | Not running on a CPU, but is ready to run (one or more higher or equal priority threads are running) |
STATE_RECEIVE | Waiting for a client to send a message |
STATE_REPLY | Waiting for a server to reply to a message |
STATE_RUNNING | Actively running on a CPU |
STATE_RWLOCK_READ | Blocked trying to acquire a non-exclusive lock of a reader/writer lock after calling pthread_rwlock_rdlock(). |
STATE_RWLOCK_WRITE | Blocked trying to acquire an exclusive lock of a reader/writer lock after calling pthread_rwlock_rdlock(). |
STATE_SEM | Waiting to acquire a semaphore |
STATE_SEND | Waiting for a server to receive a message |
STATE_SIGSUSPEND | Waiting for a signal |
STATE_SIGWAITINFO | Waiting for a signal |
STATE_STOPPED | Stopped, for example by a SIGSTOP or ThreadCtl() |
STATE_WAITPAGE | Waiting for process manager to resolve a fault on a page |
The important thing to keep in mind is that when a thread is blocked, regardless of which state it's blocked in, it consumes no CPU. Conversely, the only state in which a thread consumes CPU is the RUNNING state.
We'll see the SEND, RECEIVE, and REPLY blocked states in the Message Passing chapter. The NANOSLEEP state is used with functions like sleep(). The INTR state is used with InterruptWait(), which we'll take a look at in the Interrupts chapter. Most of the other states are discussed in this chapter.