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);Service Program Name: QP0WPTHR
Default Public Authority: *USE
Threadsafe: Yes
Signal Safe: No
The pthread_getschedparam() function retrieves the scheduling parameters of the thread. The default IBM® i scheduling policy is SCHED_OTHER and cannot be changed to another scheduling policy.
The sched_policy field of the param parameter is always returned as SCHED_OTHER. The sched_priority field of the param structure is set to the priority of the target thread at the time of the call.
Note: 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() returns only that information that was set by the pthread interfaces such as pthread_setschedparam() or a modification of the thread attribute using pthread_attr_setschedparam().
Authorities and Locks
None.
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
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
- The <pthread.h> header file. See Header files for Pthread functions.
- pthread_setschedparam()--Set Target Thread 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 <sched.h> #include <stdio.h> #include "check.h" void *threadfunc(void *parm) { printf("Inside secondary thread\n"); sleep(5); /* Sleep is not 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, ¶m); 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
API introduced: V4R3
[ Back to top | Pthread APIs | APIs by category ]