Use pthread_attr_setschedpolicy(3THR) to set the scheduling policy. The POSIX standard specifies scheduling policy attributes of SCHED_FIFO (first-in-first-out), SCHED_RR (round-robin), or SCHED_OTHER (an implementation-defined method).
SCHED_FIFO
First-In-First-Out; threads whose contention scope is system (PTHREAD_SCOPE_SYSTEM) are in real-time (RT) scheduling class if the calling process has an effective user id of 0. These threads, if not preempted by a higher priority thread, will proceed until they yield or block. SCHED_FIFO for threads that have a contention scope of process (PTHREAD_SCOPE_PROCESS) or whose calling process does not have an effective user id of 0 is based on the TS scheduling class.
SCHED_RR
Round-Robin; threads whose contention scope is system (PTHREAD_SCOPE_SYSTEM) are in real-time (RT) scheduling class if the calling process has an effective user id of 0. These threads, if not preempted by a higher priority thread, and if they do not yield or block, will execute for a time period determined by the system. SCHED_RR for threads that have a contention scope of process (PTHREAD_SCOPE_PROCESS) or whose calling process does not have an effective user id of 0 is based on the TS scheduling class.
SCHED_FIFO and SCHED_RR are optional in POSIX, and are supported for real time bound threads only.
For a discussion of scheduling, see the section Scheduling.
Prototype: int pthread_attr_setschedpolicy(pthread_attr_t *tattr, int policy);
#include <pthread.h> pthread_attr_t tattr; int policy; int ret; /* set the scheduling policy to SCHED_OTHER */ ret = pthread_attr_setschedpolicy(&tattr, SCHED_OTHER);
pthread_attr_setschedpolicy() returns zero after completing successfully. Any other return value indicates that an error occurred. When either of the following conditions occurs, the function fails and returns the corresponding value.