[Return to Bookshelf] [Contents] [Previous Section] [Next Section] [Index] [Help]


pthread_setscheduler

Changes the current scheduling policy and priority of a thread.

Syntax

pthread_setscheduler(
                     thread,
                     scheduler,
                     priority );
 


Argument Data Type Access

thread opaque pthread_t read scheduler integer read priority integer read


C Binding

int
pthread_setscheduler (
pthread_t thread,
int scheduler,
int priority);

Arguments

thread
Thread whose scheduling policy is to be changed.
scheduler
New scheduling policy value for the thread specified in thread. (Policies listed on the same line are equivalent.) Valid values are as follows:
   SCHED_FIFO
   SCHED_RR
   SCHED_FG_NP or SCHED_OTHER
   SCHED_BG_NP

See Section 2.2.3.2 for a description of the scheduling policies.

priority
New priority value of the thread specified in thread. The priority attribute is dependent upon scheduling policy. Valid values fall within one of the following ranges.


Low                 High

PRI_FIFO_MIN PRI_FIFO_MAX PRI_RR_MIN PRI_RR_MAX PRI_OTHER_MIN PRI_OTHER_MAX PRI_FG_MIN_NP PRI_FG_MAX_NP PRI_BG_MIN_NP 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). (Section 2.7 describes how to specify priorities between the minimum and maximum values.)

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

The previous policy of the thread specified in thread is returned.

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

Scheduling Successful completion. policy value -1 [EINVAL] The value specified by scheduler 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.



[Return to Bookshelf] [Contents] [Previous Section] [Next Section] [Index] [Help]