In general, a thread with a higher priority gets more processor time that one with lower priority. To be more precise, &os2; looks at thread priorities if more than one thread is internally marked as "ready".

By contrast, threads which are currently "blocked" need no CPU time anyway, so for them, priorities do not matter until they are unblocked again. Note that on your typical &os2; system, the large majority of threads will be in "blocked" state at any given point in time.

&os2; is capable of controlling thread priorities in a very refined way. It differentiates between four priority classes:

  1. "Idle time priority" (1) is the lowest priority class. This means that a thread only gets processor time if no threads of higher priority classes are running. Such threads are helpful for offloading work that needs to be done, but can be delayed until the computer has time for it. An example of such a thread is &xwp;'s own Worker thread, which keeps track of the awake Desktop objects on your system. This is fairly time-consuming, but not time-critical, so it's done with idle-time priority.

  2. "Regular priority" (2) is the priority class that most threads use. It is also the default &os2; priority class if a thread does not explicitly change its priority. Between threads of this class, &os2; dynamically varies priority levels (more on this below) to make sure that no thread of this class "starves", i.e. gets no processor time.

  3. "Foreground server priority" (4) is the second-highest priority class for threads that do not want to be influenced by the dynamic priority variations that are performed on "regular" class threads. Note that even though this class has the value 4, time-critical threads do take priority over threads of this class. &os2; still does some priority variations on threads of this class based on the activity of the thread and the system.

  4. "Time-critical priority" (3) is the highest priority class in &os2;. A thread with time-critical priority will be given processor time immediately and will not be interrupted until its work is done. Many device drivers will yield the CPU only to threads of this priority class.

    Such a thread should only use the minimum possible CPU time because it cannot be interrupted (except by other time-critical threads) and can easily hang the system. Even if it yields the CPU via DosSleep(0) (see the documentation for DosSleep in the Toolkit documentation*), other non-time-critical threads will not run. This is normally only used for network and other communications software, or CD writers, or MP3 players.

Within each priority class, a thread may set a priority level. This is a value from 0 to +31 which determines the precedence of a thread within a priority class and will only be taken into account if two threads of the same priority class compete.

A few examples: