Standards / Extensions | C or C++ | Dependencies |
---|---|---|
Single UNIX Specification, Version 3 |
both | z/OS V1R9 |
#define _UNIX03_THREADS
#include <pthread.h>
#include <sched.h>
int pthread_attr_setschedparam(pthread_attr_t *__restrict__ attr,
const struct sched_param *__restrict__ param);
pthread_attr_setschedparam() sets the scheduling priority attribute in attr using the value from param.
attr is a pointer to a thread attribute object initialized by pthread_attr_init().
param points to a user-defined scheduling parameter object used by pthread_attr_setschedparam() as the source of the thread scheduling priority attribute to set in attr. The scheduling priority member of a sched_param structure is declared as an int.
If successful, the sched_priority from param is available for subsequent calls to the pthread_getschedparam() function. However, z/OS® UNIX takes no other action based on the value of the scheduling priority stored in attr.
If successful, pthread_attr_setschedparam() returns 0; otherwise, it returns an error number.
⁄* CELEBP67 *⁄
⁄* Example using SUSv3 pthread_attr_setschedparam() interface *⁄
#define _UNIX03_THREADS 1
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <errno.h>
int main(void)
{
pthread_attr_t attr;
int rc;
struct sched_param param;
param.sched_priority = 999;
if (pthread_attr_init(&attr) == -1) {
perror("error in pthread_attr_init");
exit(1);
}
rc = pthread_attr_setschedparam(&attr, ¶m);
if (rc != 0) {
printf("pthread_attr_setschedparam returned: %d\n", rc);
printf("Error: %d, Errno_Jr: %08x\n", errno, __errno2());
exit(2);
} else {
printf("Set schedpriority to %d\n", param.sched_priority);
}
rc = pthread_attr_destroy(&attr);
if (rc != 0) {
perror("error in pthread_attr_destroy");
exit(3);
}
exit(0);
}