Scheduling algorithm variables
Several variables affect the scheduling of threads.
Some are unique to thread support; others are elaborations of process-scheduling considerations:
- Priority
- A thread's priority value is the basic indicator of its precedence in the contention for processor time.
- Scheduler run queue position
- A thread's position in the scheduler's queue of dispatchable threads reflects a number of preceding conditions.
- Scheduling policy
- This thread attribute determines what happens to a running thread at the end of the time slice.
- Contention scope
- A thread's contention scope determines whether it competes only with the other threads within its process or with all threads in the system. A pthread created with process contention scope is scheduled by the library, while those created with system scope are scheduled by the kernel. The library scheduler uses a pool of kernels threads to schedule pthreads with process scope. Generally, create pthreads with system scope, if they are performing I/O. Process scope is useful, when there is a lot of intra-process synchronizations. Contention scope is a libpthreads.a concept.
- Processor affinity
- The degree to which affinity is enforced affects performance.
The combinations of these considerations can seem complex, but you can choose from three distinct approaches when you are managing a given process:
- Default
- The process has one thread, whose priority varies with CPU consumption and whose scheduling policy is SCHED_OTHER.
- Process-level control
- The process can have one or more threads, but the scheduling policy of those threads is left as the default SCHED_OTHER, which permits the use of the existing methods of controlling nice values and fixed priorities. All of these methods affect all of the threads in the process identically. If the setpri() subroutine is used, the scheduling policy of all of the threads in the process is set to SCHED_RR.
- Thread-level control
- The process can have one or more threads. The scheduling policy of these threads is set to SCHED_RR or SCHED_FIFOn, as appropriate. The priority of each thread is fixed and is manipulated with thread-level subroutines.
The scheduling policies are described in Scheduling policy for threads.