[Prev] [Contents] [Next]

pthread_attr_getschedparam()--Get Thread Attributes Object Scheduling Parameters

Syntax

#include <pthread.h>
#include <sched.h>
int pthread_attr_getschedparam(const pthread_attr_t *attr, 
                               struct sched_param *param);
Threadsafe: Yes
Signal Safe: Yes

The pthread_attr_getschedparam() function returns the scheduling parameters attribute from the thread attributes object. The default OS/400 scheduling policy is SCHED_OTHER and cannot be changed to another scheduling policy.

The sched_policy field of the param parameter will always be returned as SCHED_OTHER. The sched_priority field of the param structure will be set to the priority of the target thread at the time of the call.

Do not use pthread_setschedparam() to set the priority of a thread if you also use another mechanism (outside of the pthread APIs) to set the priority of a thread. If you do, pthread_getschedparam() will only return that information that was set via the pthread interfaces. (pthread_setschedparam() or modification of the thread attribute using pthread_attr_setschedparam())

Parameters

attr
(Input) The address of the thread attributes object.
param
(Output) Address of variable to contain the returned scheduling parameters.

Authorities and Locks

None.

Return Value

0
pthread_attr_getschedparam() was successful.
value
pthread_attr_getschedparam() was not successful. value is set to indicate the error condition.

Error Conditions

If pthread_attr_getschedparam() 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

#define _MULTI_THREADED
#include <pthread.h>
#include <sched.h>
#include <stdio.h>
#include "check.h"

int main(int argc, char **argv)
{
  pthread_t             thread;
  int                   rc=0;
  pthread_attr_t        pta;
  struct sched_param    param;

  printf("Enter Testcase - %s\n", argv[0]);

  printf("Create a thread attributes object\n");
  rc = pthread_attr_init(&pta);
  checkResults("pthread_attr_init()\n", rc);

  printf("Get scheduling parameters\n");
  rc = pthread_attr_getschedparam(&pta, &param);
  checkResults("pthread_attr_getschedparam()\n", rc);

  printf("The thread attributes object indicates: ");
  printf("priority %d\n", param.sched_priority);

  printf("Destroy thread attributes object\n");
  rc = pthread_attr_destroy(&pta);
  checkResults("pthread_attr_destroy()\n", rc);

  printf("Main completed\n");
  return 0;
}

Output

Enter Testcase - QP0WTEST/TAGSP0
Create a thread attributes object
Get scheduling parameters
The thread attributes object indicates: priority 0
Destroy thread attributes object
Main completed



[Prev] [Contents] [Next]
Copyright © 1998, IBM Corporation. All rights reserved.
Comments? Contact
rchthrds@us.ibm.com