|
Syntax #include <pthread.h>
#include <sched.h>
int pthread_attr_setinheritsched(pthread_attr_t *attr,
int *inheritsched);
Threadsafe: Yes
Signal Safe: Yes
|
The pthread_attr_setinheritsched() function sets the inheritsched attribute in the thread attributes object specified. The inheritsched attribute should be one of PTHREAD_EXPLICIT_SCHED or PTHREAD_INHERIT_SCHED. The default inheritsched attribute is PTHREAD_EXPLICIT_SCHED, with a default priority of 0.
Use the inheritsched attribute to inherit or explicitly specify the scheduling attributes when creating new threads.
None.
If pthread_attr_setinheritsched() was not successful, the error condition returned usually indicates one of the following errors. Under some conditions, the value returned could indicate an error other than those listed here.
#define _MULTI_THREADED
#include <pthread.h>
#include <stdio.h>
#include <except.h>
#include "check.h"
void showInheritSched(pthread_attr_t *attr) {
int rc;
int inheritsched;
rc = pthread_attr_getinheritsched(attr, &inheritsched);
checkResults("pthread_attr_getinheritsched()\n", rc);
switch(inheritsched) {
case PTHREAD_EXPLICIT_SCHED:
printf("Inherit Sched - PTHREAD_EXPLICIT_SCHED\n");
break;
case PTHREAD_INHERIT_SCHED:
printf("Inherit Sched - PTHREAD_INHERIT_SCHED\n");
break;
default:
printf("Invalid inheritsched attribute!\n");
exit(1);
}
return;
}
int main(int argc, char **argv)
{
pthread_t thread;
int rc=0;
pthread_attr_t attr;
char c;
void *status;
printf("Enter Testcase - %s\n", argv[0]);
rc = pthread_attr_init(&attr);
checkResults("pthread_attr_init()\n", rc);
showInheritSched(&attr);
rc = pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
checkResults("pthread_attr_setinheritsched()\n", rc);
showInheritSched(&attr);
rc = pthread_attr_destroy(&attr);
checkResults("pthread_attr_destroy()\n", rc);
printf("Main completed\n");
return 0;
}
Output
Enter Testcase - QP0WTEST/TPSIS0 Inherit Sched - PTHREAD_EXPLICIT_SCHED Inherit Sched - PTHREAD_INHERIT_SCHED Main completed