Multithreaded Programming Guide

Setting the Thread Policy and Scheduling Parameters

Use pthread_setschedparam(3C) to modify the scheduling policy and scheduling parameters of an individual thread.

pthread_setschedparam Syntax

int pthread_setschedparam(pthread_t tid, int  policy,
    const struct sched_param *param);
#include <pthread.h>

pthread_t tid;
int ret;
struct sched_param param;
int priority;

/* sched_priority will be the priority of the thread */
sched_param.sched_priority = priority;
policy = SCHED_OTHER;

/* scheduling parameters of target thread */
ret = pthread_setschedparam(tid, 
policy, &param); 

Supported policies are SCHED_FIFO, SCHED_RR, and SCHED_OTHER.

pthread_setschedparam Return Values

pthread_setschedparam() returns zero after completing successfully. Any other return value indicates that an error occurred. When either of the following conditions occurs, the pthread_setschedparam() function fails and returns the corresponding value.



The value of the attribute being set is not valid.



The caller does not have the appropriate permission to set either the scheduling parameters or the scheduling policy of the specified thread.



The value specified by tid does not refer to an existing thread.