DESCRIPTION

The
pthread_setschedparam()
function sets the scheduling policy and parameters of the thread
thread.

policy
specifies the new scheduling policy for
thread.
The supported values for
policy,
and their semantics, are described in
sched(7).

The structure pointed to by
param
specifies the new scheduling parameters for
thread.
Scheduling parameters are maintained in the following structure:

struct sched_param {
int sched_priority; /* Scheduling priority */
};

As can be seen, only one scheduling parameter is supported.
For details of the permitted ranges for scheduling priorities
in each scheduling policy, see
sched(7).

The
pthread_getschedparam()
function returns the scheduling policy and parameters of the thread
thread,
in the buffers pointed to by
policy
and
param,
respectively.
The returned priority value is that set by the most recent
pthread_setschedparam(),
pthread_setschedprio(3),
or
pthread_create(3)
call that affected
thread.
The returned priority does not reflect any temporary priority adjustments
as a result of calls to any priority inheritance or
priority ceiling functions (see, for example,
pthread_mutexattr_setprioceiling(3)
and
pthread_mutexattr_setprotocol(3)).

RETURN VALUE

On success, these functions return 0;
on error, they return a nonzero error number.
If
pthread_setschedparam()
fails, the scheduling policy and parameters of
thread
are not changed.

ERRORS

Both of these functions can fail with the following error:

ESRCH

No thread with the ID
thread
could be found.

pthread_setschedparam()
may additionally fail with the following errors:

EINVAL

policy
is not a recognized policy, or
param
does not make sense for the
policy.

EPERM

The caller does not have appropriate privileges
to set the specified scheduling policy and parameters.

POSIX.1 also documents an
ENOTSUP
("attempt was made to set the policy or scheduling parameters
to an unsupported value") error for
pthread_setschedparam().

ATTRIBUTES

For an explanation of the terms used in this section, see
attributes(7).

Interface

Attribute

Value

pthread_setschedparam(),
pthread_getschedparam()

Thread safety

MT-Safe

CONFORMING TO

POSIX.1-2001, POSIX.1-2008.

NOTES

For a description of the permissions required to, and the effect of,
changing a thread's scheduling policy and priority,
and details of the permitted ranges for priorities
in each scheduling policy, see
sched(7).

EXAMPLE

The program below demonstrates the use of
pthread_setschedparam()
and
pthread_getschedparam(),
as well as the use of a number of other scheduling-related
pthreads functions.

In the following run, the main thread sets its scheduling policy to
SCHED_FIFO
with a priority of 10,
and initializes a thread attributes object with
a scheduling policy attribute of
SCHED_RR
and a scheduling priority attribute of 20.
The program then sets (using
pthread_attr_setinheritsched(3))
the inherit scheduler attribute of the thread attributes object to
PTHREAD_EXPLICIT_SCHED,
meaning that threads created using this attributes object should
take their scheduling attributes from the thread attributes object.
The program then creates a thread using the thread attributes object,
and that thread displays its scheduling policy and priority.

In the above output, one can see that the scheduling policy and priority
were taken from the values specified in the thread attributes object.

The next run is the same as the previous,
except that the inherit scheduler attribute is set to
PTHREAD_INHERIT_SCHED,
meaning that threads created using the thread attributes object should
ignore the scheduling attributes specified in the attributes object
and instead take their scheduling attributes from the creating thread.

COLOPHON

This page is part of release 4.13 of the Linux
man-pages
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
https://www.kernel.org/doc/man-pages/.