Comment #0 by r9shackleford — 2015-06-08T12:28:40Z
pthread_setschedprio does nothing for non-realtime threads on linux, and setting it to non-zero with a non-realtime scheduling policy is undefined behavior[1].
I believe the correct thing to do is use nice levels(as it is per-thread, not per-process in linux[2]) for thread priority[3]
[1] - sched(7) - For threads scheduled under one of the normal scheduling policies (SCHED_OTHER, SCHED_IDLE, SCHED_BATCH), sched_priority is not used in scheduling decisions (it must be specified as 0).
[2] - "The scheduling policy and parameters are in fact per-thread attributes on Linux."
"The LinuxThreads implementation deviates from the POSIX.1 specification in a number of ways, including the following ... Threads do not share a common nice value." - pthreads(7)
[3] - The dynamic priority is based on the nice value (set by nice(2), setpriority(2), or sched_setattr(2)) and
increased for each time quantum the thread is ready to run, but denied to run by the scheduler. This ensures fair progress among all SCHED_OTHER threads.
Comment #1 by robert.schadek — 2024-12-01T16:24:35Z