pthread_attr_setschedparam(3THR) sets the scheduling parameters.
Scheduling parameters are defined in the param structure; only priority is supported. Newly created threads run with this priority.
SCHED_FIFO
First-In-First-Out; threads scheduled to this policy, if not preempted by a higher priority, will proceed until completion. Threads that have a contention scope of system (PTHREAD_SCOPE_SYSTEM) are in real-time (RT) scheduling class and the calling process must have an effective user id of 0. SCHED_FIFO for threads that have a contention scope of process (PTHREAD_SCOPE_PROCESS) is based on the TS scheduling class.
SCHED_RR
Round-Robin; threads scheduled to this policy, if not pre-empted by a higher priority, will execute for a time period determined by the system. Threads that have a contention scope of system (PTHREAD_SCOPE_SYSTEM) are in real-time (RT) scheduling class and the calling process must have an effective user id of 0. SCHED_RR for threads that have a contention scope of process (PTHREAD_SCOPE_PROCESS) is based on the TS scheduling class.
Prototype: int pthread_attr_setschedparam(pthread_attr_t *tattr, const struct sched_param *param);
#include <pthread.h> pthread_attr_t tattr; int newprio; sched_param param; newprio = 30; /* set the priority; others are unchanged */ param.sched_priority = newprio; /* set the new scheduling param */ ret = pthread_attr_setschedparam (&tattr, ¶m);
Returns zero after completing successfully. Any other returned value indicates that an error occurred. If the following conditions occur, the function fails and returns the corresponding value.
You can manage pthreads priority two ways. You can set the priority attribute before creating a child thread, or you can change the priority of the parent thread and then change it back.