pthread_attr_setschedpolicy(3P) pthread_attr_setschedpolicy(3P)
pthread_attr_setschedpolicy, pthread_attr_getschedpolicy - manage
scheduling policy attributes
#include <pthread.h>
int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
int pthread_attr_getschedpolicy(const pthread_attr_t *attr,
int *opolicy);
A scheduling policy defines how threads are selected to run and for how
long they run before an alternative thread may be chosen to run. There
are four policies: SCHED_FIFO (first-in-first-out), SCHED_RR (roundrobin),
SCHED_TS (time-share) and SCHED_OTHER. The default scheduling
policy attribute value for POSIX threads is SCHED_RR. Each policy uses
thread priorities [see pthread_attr_setschedparam()] as part of their
selection criteria. Scheduling scope [see pthread_attr_setscope()]
determines the set of threads from which a selection is made using a
given policy.
Thread priorities are viewed as separate queues, managed according to the
thread scheduling policy. A thread's position on the queue determines
how likely it is to be run (if it is runnable), woken up (if it is
waiting and an event arrives), or preempted (if it is running).
SCHED_FIFO Allows a thread (once selected) to run until it blocks,
exits, or there is a higher priority thread that can run.
The priority queues are managed as follows:
o When a thread is preempted it moves to the head of its
priority queue.
o When a blocked thread becomes runnable it moves to the
tail of its priority queue.
o When a thread has its scheduling priority changed [see
pthread_setschedparam(),
pthread_mutexattr_setprotocol()] it moves to the tail
of the new priority queue.
o When a thread has its scheduling policy changed it
moves to the tail of its priority queue.
o When a thread calls sched_yield() it moves to the tail
of its priority queue.
SCHED_RR Behaves like SCHED_FIFO with the addition that the thread
will automatically move to the tail of its priority queue
when it has been running for a fixed period of time [see
Page 1
pthread_attr_setschedpolicy(3P) pthread_attr_setschedpolicy(3P)
sched_rr_get_interval()]calledaquantum. This period is
reset when it expires and whenever the thread blocks; if
the thread is preempted it resumes execution with the
unexpired portion of its scheduling period.
SCHED_TS [Toc] [Back]
SCHED_OTHER These two policies are equivalent and for POSIX threads
they behave the same as SCHED_RR.
The pthread_attr_setschedpolicy() function sets the thread scheduling
policy attribute in the object attr, to the value of policy. In order to
use the scheduling policy from the attribute object the inherit attribute
must be set to PTHREAD_EXPLICIT_SCHED (which is the default) [see
pthread_attr_setinheritsched()]. The scheduling policy for the attribute
object attr, is retrieved by pthread_attr_getschedpolicy() in the opolicy
parameter.
The policies above may also be used to indirectly change the scheduling
of process scope threads [see pthread_attr_setscope()] using the POSIX
process scheduling interfaces [see sched_setscheduler() and
sched_setparam()].
For an overview of the POSIX thread scheduling model see pthreads(3P).
On success pthread_attr_setschedpolicy() returns zero; otherwise an error
number is returned:
[EINVAL] The value of policy is not SCHED_FIFO, SCHED_RR, SCHED_TS,
or SCHED_OTHER.
pthread_attr_getschedpolicy() always returns zero.
pthread_attr_setinheritsched(3P), pthread_attr_setschedparam(3P),
pthread_attr_setscope(3P), pthread_mutex_init(3P),
pthread_setschedparam(3P), pthreads(5), sched_rr_get_interval(3P),
sched_setparam(2), sched_setscheduler(2), sched_yield(2).
PPPPaaaaggggeeee 2222 [ Back ]
|