is nice() used to change the thread priority or the process priority?

前端 未结 1 379
情书的邮戳
情书的邮戳 2020-12-31 01:30

The man page for nice says "nice() adds inc to the nice value for the calling process. So, can we use it to change the nice value for a t

相关标签:
1条回答
  • 2020-12-31 02:25

    The pthreads man page says:

    POSIX.1 also requires that threads share a range of other attributes (i.e., these attributes are process-wide rather than per-thread):

    [...]

    • nice value (setpriority(2))

    So, theoretically, the "niceness" value is global to the process and shared by all threads, and you should not be able to set a specific niceness for one or more individual threads.

    However, the very same man page also says:

    LinuxThreads

    The notable features of this implementation are the following:

    [...]

    • Threads do not share a common nice value.

    NPTL

    [...]

    NPTL still has a few non-conformances with POSIX.1:

    • Threads do not share a common nice value.

    So it turns out that both threading implementations on Linux (LinuxThreads and NPTL) actually violate POSIX.1, and you can set a specific niceness for one or more individual threads by passing a tid to setpriority() on these systems.

    0 讨论(0)
提交回复
热议问题