pthread_attr_setinheritsched()--Set Thread Attribute Inherit Scheduling Attributes
Syntax:
#include <pthread.h> #include <sched.h> int pthread_attr_setinheritsched(pthread_attr_t *attr, int *inheritsched);Service Program Name: QP0WPTHR
Default Public Authority: *USE
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 zero.
Use the inheritsched attribute to inherit or explicitly specify the scheduling attributes when creating new threads.
Authorities and Locks
None.
Parameters
- attr
- (Input) Address of thread creation attributes
- inheritsched
- (Output) Address of the variable to receive the inheritsched attribute
Return Value
- 0
- pthread_attr_setinheritsched() was successful
- value
- pthread_attr_setinheritsched() was not successful. value is set to indicate the error condition
Error Conditions
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.
- [EINVAL]
The value specified for the argument is not correct.
Related Information
- The <pthread.h> header file. See Header files for Pthread functions.
- pthread_attr_getinheritsched()--Get Thread Attribute
Object Inherit Scheduling Attributes
- pthread_attr_getschedparam()--Get Thread Attributes Object Scheduling Parameters
Example
Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.
#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
API introduced: V4R3
[ Back to top | Pthread APIs | APIs by category ]