Windows and Linux thread priority equivalence
Windows OS defines the following constants as thread priority:
- THREAD_PRIORITY_IDLE (-15)
- THREAD_PRIORITY_LOWEST (-2)
- THREAD_PRIORITY_BELOW_NORMAL (-1)
- THREAD_PRIORITY_NORMAL (0)
- THREAD_PRI开发者_JAVA百科ORITY_ABOVE_NORMAL (1)
- THREAD_PRIORITY_HIGHEST (2)
- THREAD_PRIORITY_TIME_CRITICAL (15)
And Linux has sched_get_priority_max() and sched_get_priority_min() to get thread priority range.
Is it possible to have an equivalence between Windows and Linux thread priority values ?
Default Linux priority range is between -20 (highest) and 20 (idle) with step of 1 and default of 0. Negative (raised) priorities are assignable only by superuser. Note Linux never claims -20 to be Realtime/Time Critical, and RTLinux uses a separate methods to achieve Realtime. Also note in Linux Kernel space these priorities have a different range. The -20:20 is a strictly userspace thing.
I use:
sched_get_priority_max(policy);
sched_get_priority_min(policy);
to know the priority range.
精彩评论