Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]


How to choose a priority for a thread

The two main considerations when choosing the priority of a thread are: the timing requirements of the task that the thread must accomplish, and the other tasks that are likely to be running at the same time.

[Top]


Choosing a process priority

Choose one of the four standard process priorities listed below as the basis for a range of relative priorities:

  1. EPriorityForeground

    This is the default process priority. Use this priority for:

    • The currently selected user interface application which appears in the foreground on the device screen. This application is said to have the focus.

    • Servers that do not have specific timing or response requirements.

    The UIKON framework calls User::SetPriorityControl(ETrue) so that the window server can switch applications to background when not in focus. This is known as priority control. The application can further specify how the window server makes the priority change using RWsSession::ComputeMode(). However, applications should not disable priority control to run permanently at EPriorityForeground process priority without strong justification. Priority control is irrelevant to processes without a user interface, for which it should remain disabled.

  2. EPriorityBackground

    Use this process priority for:

    • all running user interface applications except the currently selected application. These applications appear in the background on the device screen.

    • applications which do not need to respond rapidly to user actions. For example applications that do not have a graphical user interface.

  3. EPriorityHigh

    Use this process priority for system servers which should respond quickly to client requests. These servers must do minimal work at this priority level before quitting to allow other threads to run.

  4. EPriorityLow

    Use this priority for processes which can run in the background.

  5. The remaining priority values:EPriorityWindowServer,EPriorityFileServer, EPrioritySupervisor and EPriorityRealTimeServer can only be used by processes with ProtServ (Protected Server) Security Capability.

See Process-relative scheme in Priority scheme for general user-side threads in Thread priority scheme.

[Top]


Choosing the priority of a thread relative to a process

EPriorityNormal is the default relative thread priority. Choose EPriorityLess and EPriorityMuchLess to set a lower priority than the owning process. Choose EPriorityMore and EPriorityMuchMore to set a higher priority than the owning process.

Application programs and system servers with no special timing requirements running with a process priority of EPriorityForeground or EPriorityBackground should use the default relative priority EPriorityNormal for their main thread.

[Top]


Choosing a process-independent thread priority

Use process-independent thread priorities only when strictly required. Typically, this is when the thread's behaviour means that its priority must lie outside the range of relative priorities available with a chosen process priority. Such threads are used for tasks with special timing requirements, such as long running background tasks or time critical tasks.

Avoid "absolute" priorities in the middle of the range of relative priorities available with the chosen process priority. For example, consider what happens if you use EPriorityAbsoluteForegroundNormal. This is in the middle of the range of priorities relative to the EPriorityForeground process priority. If the process priority is changed to EPriorityBackground, then the thread will now pre-empt all threads that have been assigned process-relative prioriities.

Time critical tasks can be divided into those that must complete as quickly as possible and those that need to complete within a fixed time interval. The former are simply high priority tasks, the latter are known as real-time tasks. See How to choose a real-time thread priority.

[Top]


Guideline summary

[Top]


Long running background tasks

Long running tasks usually run in the background. They use a low priority thread and do not directly respond to user interaction. They generally use all the CPU time available to them and run for a period of a fraction of a second to a few seconds. Occasionally long running tasks, critical to the currently selected UI application, run at a higher priority for a few seconds.

[Top]


Special timing requirements

Tasks with special timing requirements fall into two distinct categories: