Next: , Up: Scheduling


7.1.6.1 Thread Priority

Threads have three priorities associated with them by the system, a priority, a maximum priority, and a scheduled priority. The scheduled priority is used to make scheduling decisions about the thread. It is determined from the priority by the policy (for timesharing, this means adding an increment derived from cpu usage). The priority can be set under user control, but may never exceed the maximum priority. Changing the maximum priority requires presentation of the control port for the thread's processor set; since the control port for the default processor set is privileged, users cannot raise their maximum priority to unfairly compete with other users on that set. Newly created threads obtain their priority from their task and their max priority from the thread.

— Function: kern_return_t thread_priority (thread_t thread, int prority, boolean_t set_max)

The function thread_priority changes the priority and optionally the maximum priority of thread. Priorities range from 0 to 31, where lower numbers denote higher priorities. If the new priority is higher than the priority of the current thread, preemption may occur as a result of this call. The maximum priority of the thread is also set if set_max is TRUE. This call will fail if priority is greater than the current maximum priority of the thread. As a result, this call can only lower the value of a thread's maximum priority.

The functions returns KERN_SUCCESS if the operation completed successfully, KERN_INVALID_ARGUMENT if thread is not a thread or priority is out of range (not in 0..31), and KERN_FAILURE if the requested operation would violate the thread's maximum priority (thread_priority).

— Function: kern_return_t thread_max_priority (thread_t thread, processor_set_t processor_set, int priority)

The function thread_max_priority changes the maximum priority of the thread. Because it requires presentation of the corresponding processor set port, this call can reset the maximum priority to any legal value.

The functions returns KERN_SUCCESS if the operation completed successfully, KERN_INVALID_ARGUMENT if thread is not a thread or processor_set is not a control port for a processor set or priority is out of range (not in 0..31), and KERN_FAILURE if the thread is not assigned to the processor set whose control port was presented.