[Prev] [Contents] [Next]

pthread_getschedparam()--Get Thread Scheduling Parameters

Syntax

#include <pthread.h>
#include <sched.h>
int pthread_getschedparam(pthread_t thread, int *policy,
                          struct sched_param *param);
Threadsafe: Yes
Signal Safe: No

The pthread_getschedparam() function retrieves the scheduling parameters of the thread. 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 (other than 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 like pthread_setschedparam() or a modification of the thread attribute using pthread_attr_setschedparam().

Parameters

thread
(Input) Pthread handle representing the target thread.
policy
(Output) Address of the variable to contain the scheduling policy.
param
(Output) Address of the variable to contain the scheduling parameters.

Authorities and Locks

None.

Return Value

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

Error Conditions

If pthread_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"

void *threadfunc(void *parm)
{
  printf("Inside secondary thread\n");
  sleep(5);  /* Sleep isn't a very robust way to serialize threads */
  return NULL;
}

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

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

  printf("Create thread using default attributes\n");
  rc = pthread_create(&thread, NULL, threadfunc, NULL);
  checkResults("pthread_create()\n", rc);

  printf("Get scheduling parameters\n");
  rc = pthread_getschedparam(thread, &policy, &param);
  checkResults("pthread_getschedparam()\n", rc);

  printf("The thread scheduling parameters indicate:\n"
         "policy = %d\n", policy);
  printf("priority = %d\n",
         param.sched_priority);

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

Output

Enter Testcase - QP0WTEST/TPGSP0
Create thread using default attributes
Get scheduling parameters
The thread scheduling parameters indicate:
policy = 0
priority = 0
Main completed



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