Thread priority and scheduling

The default thread creation attributes of the iSeries implementation of Pthreads uses an explicitly specified priority of DEFAULT_PRIO_NP. Some implementations inherit the scheduling priority and policy of the creating thread by default. For better performance, the iSeries implementation chooses to start each thread with an explicit priority so that, when a thread is created, the priority of the creating thread does not need to be retrieved at run-time.

An iSeries thread competes for scheduling resources against other threads in the system, not solely against other threads in the process. The scheduler is a delay cost scheduler based on several delay cost curves (priority ranges). The POSIX standard and the Single UNIX Specification refers to this as scheduling scope and scheduling policy, which cannot be changed from the default of SCHED_OTHER in this implementation.

The following Pthread APIs support a scheduling policy of only SCHED_OTHER.

The priority of a thread is specified as a number that represents the value that is added to the priority of the process. Changing the priority of the process affects the priority of all of the threads within that process. The default priority for a thread is DEFAULT_PRIO_NP, which is no change from the process priority.

On the iSeries, numerically lower priority values indicate higher priority with regard to scheduling. The pthread.h and sched.h header files define the priority constants in a way that is consistent with the threads standard, but opposite of priority specifications on the iSeries. When you specify a priority of -99 in a call to pthread_setschedparam(), the priority of the target thread is lowered to the lowest possible value.

For example, process P1 is at iSeries priority 20 and contains a thread T1 that specifies a Pthread priority adjustment of -18. Process P2 is at iSeries priority 25 and contains thread T2 that specifies a priority of -5. The result is that the system schedules the threads using the iSeries priority for T1 as 38 and for T2 as 30. The thread scheduling is specified at a system level, and although process P2 runs at a lower priority ranking than process P1, thread T2 within process P2 runs at a higher priority ranking than thread T1 in process P1, and thus gets more processing resources.


Top | Pthread APIs | APIs by category