Return Values
pthread_attr_setschedpolicy() returns zero after completing successfully. Any other return value indicates that an error occurred. When either of the following conditions occurs, the function fails and returns the corresponding value.
An attempt was made to set tattr to a value that is not valid.
An attempt was made to set the attribute to an unsupported value.
Get Scheduling Policy
pthread_attr_getschedpolicy(3THR)
Use pthread_attr_getschedpolicy(3THR) to retrieve the scheduling policy.
Prototype: int pthread_attr_getschedpolicy(pthread_attr_t *tattr, int *policy); |
#include <pthread.h> pthread_attr_t tattr; int policy; int ret; /* get scheduling policy of thread */ ret = pthread_attr_getschedpolicy (&tattr, &policy); |
Return Values
pthread_attr_getschedpolicy() 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 parameter policy is NULL or tattr is invalid.
Set Inherited Scheduling Policy
pthread_attr_setinheritsched(3THR)
Use pthread_attr_setinheritsched(3THR) to set the inherited scheduling policy.
An inherit value of PTHREAD_INHERIT_SCHED means that the scheduling policies defined in the creating thread are to be used, and any scheduling attributes defined in the pthread_create() call are to be ignored. If PTHREAD_EXPLICIT_SCHED (the default) is used, the attributes from the pthread_create() call are to be used.
Prototype: int pthread_attr_setinheritsched(pthread_attr_t *tattr, int inherit); |
#include <pthread.h> pthread_attr_t tattr; int inherit; int ret; /* use the current scheduling policy */ ret = pthread_attr_setinheritsched(&tattr, PTHREAD_EXPLICIT_SCHED); |
Return Values
pthread_attr_setinheritsched() returns zero after completing successfully. Any other return value indicates that an error occurred. When either of the following conditions occurs, the function fails and returns the corresponding value.
An attempt was made to set tattr to a value that is not valid.
An attempt was made to set the attribute to an unsupported value.
Get Inherited Scheduling Policy
pthread_attr_getinheritsched(3THR)
pthread_attr_getinheritsched(3THR) returns the scheduling policy set by pthread_attr_setinheritsched().
Prototype: int pthread_attr_getinheritsched(pthread_attr_t *tattr, int *inherit); |
#include <pthread.h> pthread_attr_t tattr; int inherit; int ret; /* get scheduling policy and priority of the creating thread */ ret = pthread_attr_getinheritsched (&tattr, &inherit); |
Return Values
pthread_attr_getinheritsched() 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 parameter inherit is NULL or tattr is invalid.
Set Scheduling Parameters
pthread_attr_setschedparam(3THR)
pthread_attr_setschedparam(3THR) sets the scheduling parameters.
Scheduling parameters are defined in the param structure; only priority is supported. Newly created threads run with this priority.
Prototype: int pthread_attr_setschedparam(pthread_attr_t *tattr, const struct sched_param *param); |
#include <pthread.h> pthread_attr_t tattr; int newprio; sched_param param; newprio = 30; /* set the priority; others are unchanged */ param.sched_priority = newprio; /* set the new scheduling param */ ret = pthread_attr_setschedparam (&tattr, ¶m); |
Return Values
pthread_attr_setschedparam() 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.
The value of param is NULL or tattr is invalid.
You can manage pthreads priority two ways. You can set the priority attribute before creating a child thread, or you can change the priority of the parent thread and then change it back.
Get Scheduling Parameters
pthread_attr_getschedparam(3THR)
pthread_attr_getschedparam(3THR) returns the scheduling parameters defined by pthread_attr_setschedparam().
Prototype: int pthread_attr_getschedparam(pthread_attr_t *tattr, const struct sched_param *param); |
#include <pthread.h> pthread_attr_t attr; struct sched_param param; int ret; /* get the existing scheduling param */ ret = pthread_attr_getschedparam (&tattr, ¶m); |
Return Values
pthread_attr_getschedparam() 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 param is NULL or tattr is invalid.