Specifying Process and Thread Priorities
- Updated2023-02-21
- 2 minute(s) read
Specifying Process and Thread Priorities
You can specify the relative importance, known as the priority, of the work being done in each process and thread. If you give your process or a thread in your process a higher priority, that process or thread is given preference over other threads that have a lower priority. This means that when there are two or more threads ready to run, the thread with the highest priority runs first.
Windows groups priorities into the following classes:
- ABOVE_NORMAL_PRIORITY_CLASS
- BELOW_NORMAL_PRIORITY_CLASS
- HIGH_PRIORITY_CLASS
- IDLE_PRIORITY_CLASS
- NORMAL_PRIORITY_CLASS
- PROCESS_MODE_BACKGROUND_BEGIN
- PROCESS_MODE_BACKGROUND_END
- REALTIME_PRIORITY_CLASS
![]() |
Note National Instruments recommends that you not set the priority of your process to real-time priority unless you do so for a very short period of time. When your process is set to real-time priority, it blocks out system interrupts while it is running. This results in the mouse, keyboard, hard disk, and other critical system features not functioning and possibly causing your system to lock up. |
All threads in a process share the same priority class. Each thread in a process has a priority that is relative to the priority class of the process. Call the Windows SDK function SetPriorityClass to set the priority of a process relative to other processes running on your system.
To specify the priority of a thread, you can call one of the following functions:
- CmtSetCurrentThreadPriority
- CmtScheduleThreadPoolFunctionAdv. If you call CmtScheduleThreadPoolFunctionAdv to schedule a function to run in a thread pool, you also can specify the priority of the thread that runs the function that you schedule. The thread pool changes the thread priority before it executes the function you schedule. The thread pool restores the thread priority to its default value after your function finishes executing. You can use CmtScheduleThreadPoolFunctionAdv to specify thread priority for threads in the default thread pool as well as for custom thread pools.
- CmtSetThreadPoolAttribute and the ATTR_TP_THREAD_PRIORITY attribute. If you create a custom LabWindows/CVI Utility Library thread pool by calling CmtNewThreadPool, you can set the default priority of the threads in the pool you create using CmtSetThreadPoolAttribute.