DG/UX 5.4R3.00 pthread_attr_setinheritsched(3T)
NAME
pthreadattrsetinheritsched, pthreadattrgetinheritsched,
pthreadattrsetscope, pthreadattrgetscope, pthreadattrsetsched,
pthreadattrgetsched, pthreadattrsetprio, pthreadattrgetprio -
control thread scheduling attributes
SYNOPSIS
#include <pthread.h>
int pthreadattrsetinheritsched(pthreadattrt *attr, int inherit);
int pthreadattrgetinheritsched(pthreadattrt *attr);
int pthreadattrsetscope(pthreadattrt *attr,
int contentionscope);
int pthreadattrgetscope(pthreadattrt attr);
int pthreadattrsetsched(pthreadattrt *attr, int scheduler);
int pthreadattrgetsched(pthreadattrt *attr);
int pthreadattrsetprio(pthreadattrt *attr, int priority);
int pthreadattrgetprio(pthreadattrt *attr);
where:
attr A pointer to a thread attributes object.
inherit An integer representing PTHREAD_INHERIT_SCHED or
PTHREAD_DEFAULT_SCHED
contentionscope An integer representing PTHREAD_SCOPE_GLOBAL or
PTHREAD_SCOPE_LOCAL
scheduler An integer representing SCHED_OTHER, SCHED_FIFO,
SCHED_RR, SCHED_DG_TS, SCHED_DG_FIFO, or
SCHED_DG_LIFO scheduling policy
priority An integer priority for a thread
DESCRIPTION
The scheduling attributes of a thread can be specified when a thread
is created. Furthermore, some scheduling attributes, namely the
thread's scheduling policy and priority, can be changed after a
thread has been created.
The inheritsched attribute determines whether newly created threads
should inherit the scheduling attributes of the creating thread
(default), or should use the scheduling attributes described next.
In other words, if scheduling is to be inherited, all of the
scheduling attributes discussed next are ignored.
There are two levels of scheduling in the system: local and global.
For threads not inheriting scheduling parameters, the contentionscope
attribute determines if the thread is scheduled locally or globally.
A locally scheduled thread is scheduled against other threads in its
process. A globally scheduled thread is scheduled against all other
Licensed material--property of copyright holder(s) 1
DG/UX 5.4R3.00 pthread_attr_setinheritsched(3T)
processes and globally scheduled threads in the system.
Once the scope of the thread has been specified, its scheduling
policy and priority determine how it will be scheduled within that
scope. The scheduling policies and priority ranges are the same as
those specified in the Posix 1003.4 Realtime standard, except that
they apply to threads instead of processes. Refer to <sched.h>,
schedsetscheduler(2), and schedsetparam(2) for a discussion of
these scheduling policies and priorites as used for processes. A
similar discussion applies to threads.
Strictly speaking, the unit of global scheduling in the system is the
thread group, not the process. By default, a process has only one
thread group, called the Initial Thread Group. A locally scheduled
thread is scheduled against other threads in its thread group. For a
default process, this equates to scheduling the thread against all
other locally scheduled threads in the process.
A globally scheduled thread is given its own dedicated thread group.
The thread will, in essence, be scheduled against all other thread
groups in the system. The thread's dedicated thread group is given
the same scheduling policy and priority as the thread. However, the
thread's local scheduling policy and priority are irrelevant, as the
thread is the only thread in its dedicated thread group from which to
choose.
By default, a locally-scheduled thread is created in the thread group
of its creator, unless the creator is itself globally scheduled, in
which case the thread is created in the process's Initial Thread
Group. Refer to dgpthreadattrsetgroup(3T) for a discussion on
specifying a different thread group for a newly created thread.
For a thread inheriting the scheduling attributes of its creator, the
new thread will naturally inherit the scheduling scope of its
creator. If the creator is locally scheduled, then the new thread
will be locally scheduled in the same thread group as the creator.
If the creator is globally scheduled, then the new thread will be
globally scheduled in its own dedicated thread group, which will be a
clone of the creator's dedicated thread group. In either case, the
new thread will inherit the scheduling policy and priority of its
creator.
Once a thread has been created at a particular scope and in a
particular thread group, its scope and thread group may not be
changed for the life of the thread. Only the thread's scheduling
policy and priority may be changed. Refer to
pthreadsetschedattr(3T) for a discussion on changing the scheduling
attributes of an existing thread.
The following functions control thread scheduling attributes:
pthreadattrsetinheritsched() and pthreadattrgetinheritsched()
These functions set and get the inheritsched attribute in the
attributes object pointed to by the attr argument. When attribute
Licensed material--property of copyright holder(s) 2
DG/UX 5.4R3.00 pthread_attr_setinheritsched(3T)
objects are used by pthreadcreate(), the inheritsched attribute
determines how the other scheduling attributes of the created thread
are to be set.
The following symbols are defined in the header <pthread.h>:
PTHREAD_INHERIT_SCHED The scheduling policy and priority are
to be inherited from the creating
thread. This is the default.
PTHREAD_DEFAULT_SCHED The scheduling policy and priority are
to be set to the corresponding values
from this attributes object.
pthreadattrsetscope() and pthreadattrgetscope()
These functions set and get the contentionscope attribute in the
attributes object pointed to by attr. The valid values for the
contentionscope attribute represent the following symbols defined by
the header <pthread.h>:
PTHREAD_SCOPE_GLOBAL Global contention scope
PTHREAD_SCOPE_LOCAL Local contention scope
pthreadattrsetsched(), and pthreadattrgetsched()
These functions set and get the scheduling policy attribute in the
attributes object pointed to by attr.
The scheduler attribute defines the scheduling policy of threads.
The scheduler values are defined by the header <sched.h> and have the
following meanings:
SCHED_OTHER Default DG/UX scheduling policy, which is the
same as SCHED_DG_TS, the timesharing scheduling
policy
SCHED_FIFO First-in first-out, which means that the thread
runs until it blocks or is preempted by a higher
priority thread
SCHED_RR Round robin, which is the same as SCHED_FIFO,
except the thread yields to peers when it runs
out a timeslice
SCHED_DG_TS DG/UX timesharing scheduling policy, which is the
same as SCHED_OTHER
SCHED_DG_FIFO
Same as SCHED_FIFO, except the entire range of
priorities are allowed. This is a hard realtime
scheduling policy.
SCHED_DG_LIFO
Last-in first-out, which means that unblocked
threads will be placed before other threads of
equal priority; otherwise this policy is the same
as SCHED_DG_FIFO.
pthreadattrsetprio() and pthreadattrgetprio()
These functions set and get the priority attribute in the attributes
object pointed to by attr. The allowed priority range for each
scheduling policy can be obtained using calls to
schedprioritygetmax(2) and schedprioritygetmin(2).
Licensed material--property of copyright holder(s) 3
DG/UX 5.4R3.00 pthread_attr_setinheritsched(3T)
DIAGNOSTICS
Return Value
If successful, pthreadattrgetinheritsched(),
pthreadattrgetscope(), pthreadattrgetsched(), and
pthreadattrgetprio() return the inheritsched, contentionscope,
scheduler, and priority attributes, respectively. Otherwise, they
return -1 and set errno to indicate the error.
If successful, pthreadattrsetinheritsched(),
pthreadattrsetscope(), pthreadattrsetsched(), and
pthreadattrsetprio() change the values for the inheritsched,
contentionscope, scheduler, and priority attributes, respectively,
and return 0. Otherwise, they return -1 and set errno to indicate
the error.
Errors
For each of the following conditions, pthreadattrsetinheritsched(),
pthreadattrgetinheritsched(), pthreadattrsetscope(),
pthreadattrgetscope(), pthreadattrsetsched(),
pthreadattrgetsched(), pthreadattrsetprio(),
pthreadattrgetprio() return -1 and set errno to the corresponding
value:
[EINVAL] An invalid attributes object has been specified. This
occurs when DG/UX has detected that the attributes object
pointed to by attr has not been initialized by a previous
call to pthreadattrinit() or has been corrupted.
For each of the following conditions, pthreadattrsetinheritsched()
returns -1 and sets errno to the corresponding value:
[EINVAL] The value of inherit is not PTHREADINHERITSCHED or
PTHREADDEFAULTSCHED.
For each of the following conditions, pthreadattrsetscope() returns
-1 and sets errno to the corresponding value:
[EINVAL] The value of contentionscope is not PTHREADSCOPELOCAL or
PTHREADSCOPEGLOBAL.
For each of the following conditions, pthreadattrsetsched() returns
-1 and sets errno to the corresponding value:
[EINVAL] The value of scheduler is not one of the supported
scheduling policies.
For each of the following conditions, pthreadattrsetprio() returns
-1 and sets errno to the corresponding value:
[EINVAL] The value of prio is outside the absolute range of
priorities allowed on the system.
SEE ALSO
pthreadattrinit(3T), pthreadcreate(3T), pthreadsetschedattr(3T),
Licensed material--property of copyright holder(s) 4
DG/UX 5.4R3.00 pthread_attr_setinheritsched(3T)
pthreadyield(3T), schedgetprioritymax(2),
schedgetprioritymin(2), schedsetscheduler(2), schedsetparam(2),
schedyield()(2), dgpthreadattrsetgroup(3T),
dgpthreadgroupcreate(3T), threads(5).
NOTES
The DG/UX system defines the {_POSIX_THREAD_PRIORITY_SCHEDULING}
symbol, indicating that the aforementioned standard scheduling
attributes are supported.
The exact meanings of local vs. global scopes vary from system to
system.
An application should not make any assumptions about the absolute
priority ranges for the supported scheduling policies, other than
SCHEDFIFO and SCHEDRR having higher priority ranges than
SCHEDOTHER. The absolute values for the ranges can change from
release to release. An application should use relative values or
make queries using schedpriorityget{min,max}().
Note that, if an application specifies a priority value that is out-
of-range for the desired scheduling policy, the error will not occur
until the attributes object is used in a call to pthreadcreate() or
pthreadsetschedattr(). The only case where it will be caught by
pthreadattrsetprio() is where the priority value is out-of-range of
the absolute priority values allowed on the system as a whole.
Similarly, permissions are not checked until an attributes object is
actually used on a thread. In general, no special permissions are
required to set the scheduling policy and priority for a locally
scheduled thread. On the other hand, special permission may be
required to explicitly set these attributes for a globally scheduled
thread. Inheriting attributes never requires special permissions.
Licensed material--property of copyright holder(s) 5