26.02.2014 Views

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The kernel’s role<br />

© 2009, <strong>QNX</strong> <strong>Software</strong> <strong>Systems</strong> GmbH & Co. KG.<br />

longer-waiting threads, the kernel has some flexibility as to when to schedule them to<br />

avoid inefficiency in the use of the cache. For more information about SMP, see the<br />

Multicore Processing User’s Guide.<br />

Kernel states<br />

We’ve been talking about “running,” “ready,” and “blocked” loosely — let’s now<br />

formalize these thread states.<br />

RUNNING<br />

<strong>Neutrino</strong>’s RUNNING state simply means that the thread is now actively consuming<br />

the CPU. On an SMP system, there will be multiple threads running; on a<br />

single-processor system, there will be one thread running.<br />

READY<br />

The READY state means that this thread could run right now — except that it’s not,<br />

because another thread, (at the same or higher priority), is running. If two threads<br />

were capable of using the CPU, one thread at priority 10 and one thread at priority 7,<br />

the priority 10 thread would be RUNNING and the priority 7 thread would be READY.<br />

The blocked states<br />

Kernel states, the complete list<br />

What do we call the blocked state? The problem is, there’s not just one blocked state.<br />

Under <strong>Neutrino</strong>, there are in fact over a dozen blocking states.<br />

Why so many? Because the kernel keeps track of why a thread is blocked.<br />

We saw two blocking states already — when a thread is blocked waiting for a mutex,<br />

the thread is in the MUTEX state. When a thread is blocked waiting for a semaphore,<br />

it’s in the SEM state. These states simply indicate which queue (and which resource)<br />

the thread is blocked on.<br />

If a number of threads are blocked on a mutex (in the MUTEX blocked state), they get<br />

no attention from the kernel until the thread that owns the mutex releases it. At that<br />

point one of the blocked threads is made READY, and the kernel makes a rescheduling<br />

decision (if required).<br />

Why “if required?” The thread that just released the mutex could very well still have<br />

other things to do and have a higher priority than that of the waiting threads. In this<br />

case, we go to the second rule, which states, “The highest-priority ready thread will<br />

run,” meaning that the scheduling order has not changed — the higher-priority thread<br />

continues to run.<br />

Here’s the complete list of kernel blocking states, <strong>with</strong> brief explanations of each state.<br />

By the way, this list is available in — you’ll notice that the<br />

states are all prefixed <strong>with</strong> STATE_ (for example, “READY” in this table is listed in<br />

the header file as STATE_READY):<br />

24 Chapter 1 • Processes and Threads April 30, 2009

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!