#include <pthread.h> #include <sched.h> int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inheritsched);Service Program Name: QP0WPTHR
The pthread_attr_getinheritsched() function returns the inheritsched attribute from the thread attributes object specified. The inheritsched attribute is 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 parameter to inherit or explicitly specify the scheduling attributes when creating new threads.
None.
If pthread_attr_getinheritsched() 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.
The value specified for the argument is not correct.
See Code disclaimer information for information pertaining to code examples.
#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/TPGIS0 Inherit Sched - PTHREAD_EXPLICIT_SCHED Inherit Sched - PTHREAD_INHERIT_SCHED Main completed
Top | Pthread APIs | APIs by category |