Set a thread's priority
#include <pthread.h> int pthread_setschedprio( pthread_t thread, int prio );
- The ID of the thread that you want to get the scheduling parameters for. You can get a thread ID by calling pthread_create() or pthread_self().
- The new scheduling priority.
As an extension to POSIX, you can wrap the new priority in one these macros to specify how to handle out-of-range priority requests:
- SCHED_PRIO_LIMIT_ERROR(prio) — indicate an error
- SCHED_PRIO_LIMIT_SATURATE(prio) — saturate at the maximum allowed priority
If procnto was started with a -P option ending with s or S, out-of-range priority requests by default saturate at the maximum allowed value.
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The pthread_setschedprio() function sets the priority of thread thread to prio.
If the thread is running or runnable, the effect on its position in the ready queue depends on the direction of the modification:
- If you raise the priority, the thread becomes the tail of the ready queue for that priority.
- If you don't change the priority, the thread doesn't change position in the ready queue.
- If you lower the priority, the thread becomes the head of the ready queue for that priority.
The pthread_setschedprio() function gives you a way to temporarily raise a thread's priority and lower it again, without yielding to other threads of the same priority. This is necessary if you have to implement your own strategies for bounding priority inversion, such as priority inheritance or priority ceilings.
In order to change its priority to a value above the maximum permitted for unprivileged processes, your process must have the PROCMGR_AID_PRIORITY ability enabled. For more information, see procmgr_ability().
- The priority isn't valid for the scheduling policy of the specified thread.
- The specified priority isn't supported.
- The calling process doesn't have the required permission; see procmgr_ability().
- Invalid thread ID thread.
Last modified: 2014-06-24