|
Syntax #include <pthread.h>
#include <sched.h>
int pthread_attr_setschedparam(pthread_attr_t *attr,
const struct sched_param *param);
Threadsafe: Yes
Signal Safe: Yes
|
The pthread_attr_setschedparam() function sets the scheduling parameters in the thread attributes object. The supported OS/400 scheduling policy is SCHED_OTHER, attempting to set a the sched_policy field of the param parameter other than SCHED_OTHER will result in the EINVAL error. The sched_priority field of the param parameter must range from PRIORITY_MIN to PRIORITY_MAX or the ENOTSUP error will occur.
All reserved fields in the scheduling parameters structure must be binary 0 or the EINVAL error will occur.
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())
None.
If pthread_attr_setschedparam() 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.
#define _MULTI_THREADED
#include <pthread.h>
#include <sched.h>
#include <stdio.h>
#include "check.h"
#define BUMP_PRIO 1
static int thePriority = 0;
void showSchedParam(pthread_attr_t *a)
{
int rc=0;
struct sched_param param;
printf("Get scheduling parameters\n");
rc = pthread_attr_getschedparam(a, ¶m);
checkResults("pthread_attr_getschedparam()\n", rc);
printf("The thread attributes object indicates priority: %d\n",
param.sched_priority);
thePriority = param.sched_priority;
return;
}
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);
showSchedParam(&pta);
memset(¶m, 0, sizeof(param));
if (thePriority + BUMP_PRIO <= PRIORITY_MAX_NP) {
param.sched_priority = thePriority + BUMP_PRIO;
}
printf("Setting scheduling parameters\n");
rc = pthread_attr_setschedparam(&pta, ¶m);
checkResults("pthread_attr_setschedparam()\n", rc);
showSchedParam(&pta);
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/TASSP0 Create a thread attributes object Get scheduling parameters The thread attributes object indicates priority: 0 Setting scheduling parameters Get scheduling parameters The thread attributes object indicates priority: 0 Destroy thread attributes object Main completed