pthread_attr_setsched(3) — Subroutines
NAME
pthread_attr_setsched − Changes the scheduling policy attribute of thread creation.
SYNOPSIS
#include <pthread.h>
int pthread_attr_setsched(
pthread_attr_t ∗attr ,
int scheduler );
PARAMETERS
attrThreads attributes object modified.
schedulerNew value for the scheduling policy attribute. 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(Default) All threads are timesliced. SCHED_OTHER ensures that all threads, regardless of priority, receive some scheduling so no thread is completely denied execution time. (However, SCHED_OTHER threads can be denied execution time by SCHED_FIFO or SCHED_RR threads.)
DESCRIPTION
This routine sets the scheduling policy of a thread that is created using the attributes object specified by the attr argument. The default value of the scheduling attribute is SCHED_OTHER.
By default, a created thread inherits the priority of the thread calling pthread_create. To specify a priority using this routine, scheduling inheritance must be disabled at the time the thread is created. Call pthread_attr_setinheritsched and specify the value PTHREAD_DEFAULT_SCHED for the inherit argument before calling pthread_create.
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 scheduler is invalid. |
| −1 | [ESRCH] | The value specified by attr does not refer to an existing thread attributes object. |
RELATED INFORMATION
pthread_attr_create(3), pthread_attr_getsched(3), pthread_attr_setinheritsched(3), pthread_create(3)