pthread_setscheduler(3) — Subroutines
Digital
NAME
pthread_setscheduler − Changes the current scheduling policy and priority of a thread.
SYNOPSIS
#include <pthread.h>
int pthread_setscheduler(
pthread_t thread ,
int scheduler ,
int priority );
PARAMETERS
threadThread whose scheduling policy is to be changed.
schedulerNew scheduling policy value for the thread specified in thread. Valid values are as follows:
SCHED_FIFO(First In, First Out) The highest priority thread runs until it blocks. If there is more than one thread with the same priority, and that priority is the highest among other threads, the first thread to begin running continues until it blocks.
SCHED_RR(Round Robin) The highest priority thread runs until it blocks; however, threads of equal priority, if that priority is the highest among other threads, are timesliced. Timeslicing is a process in which threads alternate using available processors.
SCHED_OTHER
"SCHED_FG_NP" (Default) All threads are timesliced. SCHED_OTHER ensures that all threads, regardless of priority, receive some scheduling, and thus no thread is completely denied execution time. (However, SCHED_OTHER threads can be denied execution time by SCHED_FIFO or SCHED_RR threads.)
SCHED_BG_NP(Background) Like SCHED_OTHER, ensures that all threads, regardless of priority, receive some scheduling. However, SCHED_BG_NP may be denied execution by any of the other scheduling policies.
priorityNew priority value of the thread specified in thread. The priority attribute is dependent upon scheduling policy. Valid values fall within one of the following five ranges:
PRI_OTHER_MIN <= priority <= PRI_OTHER_MAX
PRI_FIFO_MIN <= priority <= PRI_FIFO_MAX
PRI_RR_MIN <= priority <= PRI_RR_MAX
PRI_FG_MIN_NP <= priority <= PRI_FG_MAX_NP
PRI_BG_MIN_NP <= priority <= PRI_BG_MAX_NP
If you create a new thread without specifying a threads attributes object that contains a changed priority attribute, the default priority of the newly created thread is the midpoint between PRI_OTHER_MIN and PRI_OTHER_MAX (the midpoint between the minimum and the maximum for the SCHED_OTHER policy).
When you call this routine to specify a minimum or maximum priority, use the appropriate symbol — for example, PRI_FIFO_MIN or PRI_FIFO_MAX. To specify a value between the minimum and maximum, use an appropriate arithmetic expression. For example, to specify a priority mid-way between the minimum and maximum for the Round Robin scheduling policy, specify the following concept using your programming language’s syntax:
pri_rr_mid = (PRI_RR_MIN + PRI_RR_MAX)/2
If your expression results in a value outside the range of minimum to maximum, an error results when you use it.
DESCRIPTION
This routine changes the current scheduling policy and priority of a thread. Call this routine to change both the priority and scheduling policy of a thread at the same time. To change only the priority, call the pthread_setprio routine.
A thread changes its own scheduling policy and priority by using the identifier returned by pthread_self. Changing the scheduling policy or priority, or both, of a thread can cause it to start executing or to be preempted by another thread.
This routine is different from pthread_attr_setprio and pthread_attr_setsched because those routines set the priority and scheduling policy attributes that are used to establish the priority and scheduling policy of a new thread when it is created. This routine, however, changes the priority and scheduling policy of an existing thread.
RETURN VALUES
If an error condition occurs, this routine returns −1 and sets errno to the corresponding error value. Possible return values are as follows:
| Return | Error | Description |
| 0 | Successful completion. | |
| −1 | [EINVAL] | The value specified by thread is invalid. |
| −1 | [ENOTSUP] | An attempt is made to set the policy to an unsupported value. |
| −1 | [ESRCH] | The value specified by thread does not refer to an existing thread. |
| −1 | [EPERM] | The caller does not have the appropriate privileges to set the priority of the specified thread. |
RELATED INFORMATION
pthread_attr_setprio(3), pthread_attr_setsched(3), pthread_create(3), pthread_self(3), pthread_setprio(3)