Internally the scheduler always deals with nanokernel threads, NThread objects, and their associated priority between 0 (lowest) and 63 (highest). In general, a thread with a higher priority that is ready to run will always run in preference to threads with a lower priority. The only exception is where a higher priority thread waits on a nanokernel fast mutex held by a lower priority thread. In this case, the higher priority thread will yield to the lower priority thread holding the mutex.
A Symbian OS thread, a DThread object, has an embedded NThread, which enables it to be scheduled by the nanokernel.
There are two ways of setting a priority for Symbian OS thread:
using the two-level priority scheme
using an absolute priority.
In this scheme, a Symbian OS thread priority is relative to the priority of its owning process. By default, Symbian OS threads inherit the priority of their owning process when they are created. This priority can be raised or lowered relative to the process priority - this just sets the thread’s priority to the process priority plus or minus a specified priority weighting. If the priority of the process is changed, the priority of its threads will change relative to other threads in the system but will remain the same relative to each other.
The default priority of a process is EPriorityForgeround, which is an absolute priority of 350. Threads by default are created with relative priority EPriorityNormal which sets them to the same priority as the owning process. The window server lowers the priority of background UI processes to EPriorityBackground (250).
The NULL thread, also known as the idle thread, runs at priority 0, and means that it will only run when there are no other threads ready to run.
Symbian OS thread priorities map onto NThread priorities in the range 1 to 31 as shown in the table below.
|
where:
the process priority values are defined by the internal Symbian OS enum TProcPriority, defined in ...\e32\include\kernel\kern_priv.h. The symbols in the table correspond to the symbols in the enum.
the thread priority values are defined by the internal Symbian OS enum TThrdPriority, defined in ...\e32\include\kernel\kern_priv.h. The symbols in the table correspond to the symbols in the enum.
It is possible to set an absolute priority that is not relative to the process priority; it is not affected by changes in the process priority.