pthread_attr_getinheritsched()--Get Thread Attribute Object Inherit Scheduling Attributes


  Syntax:
 #include <pthread.h>
 #include <sched.h>
 int pthread_attr_getinheritsched(const pthread_attr_t *attr,  
                                 int *inheritsched); 
  Service Program Name: QP0WPTHR

  Default Public Authority: *USE

  Threadsafe: Yes

  Signal Safe: Yes

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.


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_getinheritsched() was successful.
value
pthread_attr_getinheritsched() was not successful. value is set to indicate the error condition.

Error Conditions

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.

[EINVAL]

The value specified for the argument is not correct.


Related Information


Example

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


API introduced: V4R3
Top | Pthread APIs | APIs by category