#include <pthread.h> #include <sched.h> int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param);Service Program Name: QP0WPTHR
The pthread_getschedparam() function retrieves the scheduling parameters of the thread. The default i5/OS 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().
None.
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.
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 <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
Top | Pthread APIs | APIs by category |