Name

pthread_setschedparam, pthread_getschedparam
- thread scheduling parameter manipulation

Library

libc_r.lib libpthread.lib libthr.lib

Synopsis

  #include <pthread.h>
  int pthread_setschedparam (pthread_t thread, int policy, const struct sched_param *param);
  int pthread_getschedparam (pthread_t thread, int *policy, struct sched_param *param);

Return values

If successful, these functions return 0. Otherwise, an error number is returned to indicate the error.

Detailed description

The pthread_setschedparam and pthread_getschedparam functions set and get the scheduling parameters of individual threads. The scheduling policy for a thread will be SCHED_RR (round-robin). ( SCHED_FIFO is not supported) The thread priority (accessed via param->sched_priority) must be at least PTHREAD_MIN_PRIORITY and no more than PTHREAD_MAX_PRIORITY.

Examples

struct sched_param sparam;
int policy, priority, policy_1;
int rc;
policy = SCHED_RR;
priority = 50;
sparam.sched_priority = priority;
rc = pthread_setschedparam(pthread_self(), policy, &sparam);
if (rc != 0)
{
  printf("Error at pthread_setschedparam: rc=%d\n", rc);
  return -1;
}

         

int e ;
struct sched_param param;
pthread_t thread; // Thread which will be assigned the scheduling priority and the policy.
pthread_t thread = pthread_self();
param.sched_priority = 100;
 
e = pthread_setschedparam(thread,SCHED_RR, & param);
if(e != 0)
{
   printf("setting scheduling policy and priority failed."));
   return -1;
}

         

int e ;
struct sched_param param;
pthread_t thread; // Thread which will be assigned the scheduling priority and the policy.
int policy;
pthread_t thread = pthread_self();
param.sched_priority = 100;
 
e = pthread_setschedparam(thread,SCHED_RR, & param);
if(e != 0)
{
   printf("setting scheduling policy and priority failed."));
   return -1;
}
e = pthread_getschedparam(thread,&policy,& param);
if (e != 0)
{
   printf("getting scheduling policy and priority failed."));
   return -1;
}

         

Limitation

Only SCHED_RR policy is supported.


Errors

The pthread_setschedparam function will fail if:
[EINVAL]
  Invalid value for policy or param
[ENOTSUP]
  Invalid value for scheduling parameters.
[ESRCH]
  Non-existent thread thread.

The pthread_getschedparam function will fail if:

[ESRCH]
  Non-existent thread thread.


Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top