Return Value
pthread_attr_getguardsize() fails if:
EINVAL
The argument attr is invalid, the argument guardsize is invalid, or the argument guardsize contains an invalid value.
Set Scope
pthread_attr_setscope(3THR)
Use pthread_attr_setscope(3THR) to create a bound thread (PTHREAD_SCOPE_SYSTEM) or an unbound thread (PTHREAD_SCOPE_PROCESS).
Note - Both thread types are accessible only within a given process.
Prototype: int pthread_attr_setscope(pthread_attr_t *tattr,int scope); |
#include <pthread.h> pthread_attr_t tattr; int ret; /* bound thread */ ret = pthread_attr_setscope(&tattr, PTHREAD_SCOPE_SYSTEM); /* unbound thread */ ret = pthread_attr_setscope(&tattr, PTHREAD_SCOPE_PROCESS); |
Notice that there are three function calls in this example: one to initialize the attributes, one to set any variations from the default attributes, and one to create the pthreads.
#include <pthread.h> pthread_attr_t attr; pthread_t tid; void start_routine; void arg; int ret; /* initialized with default attributes */ ret = pthread_attr_init (&tattr); /* BOUND behavior */ ret = pthread_attr_setscope(&tattr, PTHREAD_SCOPE_SYSTEM); ret = pthread_create (&tid, &tattr, start_routine, arg); |
Return Values
pthread_attr_setscope() returns zero after completing successfully. Any other return value indicates that an error occurred. If the following conditions occur, the function fails and returns the corresponding value.
An attempt was made to set tattr to a value that is not valid.
Get Scope
pthread_attr_getscope(3THR)
Use pthread_attr_getscope(3THR) to retrieve the thread scope, which indicates whether the thread is bound or unbound.
Prototype: int pthread_attr_getscope(pthread_attr_t *tattr, int *scope); |
#include <pthread.h> pthread_attr_t tattr; int scope; int ret; /* get scope of thread */ ret = pthread_attr_getscope(&tattr, &scope); |
Return Values
pthread_attr_getscope() returns zero after completing successfully. Any other return value indicates that an error occurred. If the following condition occurs, the function fails and returns the corresponding value.
The value of scope is NULL or tattr is invalid.
Set Thread Concurrency Level
pthread_setconcurrency(3THR)
pthread_setconcurrency(3THR) is provided for standards compliance. It is used by an application to inform the threads library of its desired concurrency level. For the threads implementation introduced in Solaris 9, this interface has no effect; all runnable threads are attached to LWPs.
#include <pthread.h> int pthread_setconcurrency(int new_level); |
Return Value
pthread_setconcurrency() fails if:
EINVAL
The value specified by new_level is negative.
EAGAIN
The value specified by new_level would cause a system resource to be exceeded.
Get Thread Concurrency Level
pthread_getconcurrency(3THR)
pthread_getconcurrency(3THR) returns the value set by a previous call to pthread_setconcurrency(). If the pthread_setconcurrency() function was not previously called, pthread_getconcurrency() returns zero.
#include <pthread.h> int pthread_getconcurrency(void); |
Return Value
pthread_getconcurrency() always returns the concurrency level set by a previous call to pthread_setconcurrency(). If pthread_setconcurrency() has never been called, pthread_getconcurrency() returns zero.
Set Scheduling Policy
pthread_attr_setschedpolicy(3THR)
Use pthread_attr_setschedpolicy(3THR) to set the scheduling policy. The POSIX standard specifies scheduling policy attributes of SCHED_FIFO (first-in-first-out), SCHED_RR (round-robin), or SCHED_OTHER (an implementation-defined method).
SCHED_FIFO
First-In-First-Out; threads whose contention scope is system (PTHREAD_SCOPE_SYSTEM) are in real-time (RT) scheduling class if the calling process has an effective user id of 0. These threads, if not preempted by a higher priority thread, will proceed until they yield or block. SCHED_FIFO for threads that have a contention scope of process (PTHREAD_SCOPE_PROCESS) or whose calling process does not have an effective user id of 0 is based on the TS scheduling class.
SCHED_RR
Round-Robin; threads whose contention scope is system (PTHREAD_SCOPE_SYSTEM) are in real-time (RT) scheduling class if the calling process has an effective user id of 0. These threads, if not preempted by a higher priority thread, and if they do not yield or block, will execute for a time period determined by the system. SCHED_RR for threads that have a contention scope of process (PTHREAD_SCOPE_PROCESS) or whose calling process does not have an effective user id of 0 is based on the TS scheduling class.
SCHED_FIFO and SCHED_RR are optional in POSIX, and are supported for real time bound threads only.
For a discussion of scheduling, see the section "Scheduling".
Prototype: int pthread_attr_setschedpolicy(pthread_attr_t *tattr, int policy); |
#include <pthread.h> pthread_attr_t tattr; int policy; int ret; /* set the scheduling policy to SCHED_OTHER */ ret = pthread_attr_setschedpolicy(&tattr, SCHED_OTHER); |