Operating System - Linux
1826301 Members
4223 Online
109692 Solutions
New Discussion

pthread_create fails when used with pthread_attr_setinheritsched() on HPUX

 
jeet_xp
Occasional Advisor

pthread_create fails when used with pthread_attr_setinheritsched() on HPUX

I am using HPUX on Itanium and I have c program where I am doing something like this
but this pthread_create always fails at runtime
prio = PRI_MAX;
prio_low = PRI_MIN;
.
.
.
.
struct sched_param sched_param={1};
sched_param.sched_priority=prio;
thret = pthread_attr_setschedparam(&serv_attr, &sched_param);

thret = pthread_attr_setinheritsched(&serv_attr,PTHREAD_EXPLICIT_SCHED);

.
.
.
thret = pthread_create(&sthread,&serv_attr,server_main, 0);
The error code for a user it EPERM and for root it is EINVAL.
but if i remove this line

thret = pthread_attr_setinheritsched(&serv_attr,PTHREAD_EXPLICIT_SCHED);

it works fine, can anyone suggest whats happening here. I have tried the same code on AIX and Solaris without any changes, it works there.
4 REPLIES 4
Dennis Handly
Acclaimed Contributor

Re: pthread_create fails when used with pthread_attr_setinheritsched() on HP-UX

Have you called pthread_attr_init?

Why are you using {1} above? It is illegal to hardcode constants. Did you mean to use SCHED_RR?

Both EPERM and EINVAL seem to point out that your scheduling values isn't valid:
[EPERM] The caller does not have the appropriate privileges to create a thread with the scheduling policy and parameters specified in attr.

[EINVAL] The scheduling policy or scheduling attributes specified in attr are invalid.

Have you read rtsched(2)?

rick jones
Honored Contributor

Re: pthread_create fails when used with pthread_attr_setinheritsched() on HPUX

Or at the very least, unwise to ass-u-me that different OSes will have the same values for constants of the same name, unless those values are specified by a de jure standard.
there is no rest for the wicked yet the virtuous have no pillows
jeet_xp
Occasional Advisor

Re: pthread_create fails when used with pthread_attr_setinheritsched() on HPUX

yes i have called this API
pthread_attr_init()

I have also read the rtsched(2)
which gives me info about these

sched_get_priority_max()
sched_get_priority_min()
PRI_HPUX_TO_POSIX()
PRI_POSIX_TO_HPUX()

which are significant in my program i guess.
But still I am facing the problem.

I have found one more interesting thing about
sched_param structure which is something like this in HPUX

struct sched_param {
int sched_priority; /* Process execution scheduling priority. */
int sched_reserved[7]; /* Reserved fields for future expansion. */
};


and for AIX and solaris

struct sched_param
{
int sched_priority;
int sched_policy;
int sched_reserved[6];
};


on solaris

struct sched_param {
int sched_priority; /* process execution scheduling priority */
int sched_nicelim; /* nice value limit for SCHED_OTHER policy */
int sched_nice; /* nice value for SCHED_OTHER policy */
int sched_pad[6]; /* pad to the same size as pcparms_t of */
/* sys/priocntl.h */
/* sizeof(sched_priority) + */
/* sizeof(pcparms_t.pc_clparms) */
};


here as you can see i can set policy in this structure something like this

struct sched_param sched_param={1,1,1};

but in HPUX i am using sched_param sched_param={1}

this only sets the first parameter which is scheduling priority. As you have asked me whether I am setting the policy or not my answer is no, I am not setting it.
please suggest something.
Dennis Handly
Acclaimed Contributor

Re: pthread_create fails when used with pthread_attr_setinheritsched() on HP-UX

>I have also read the rtsched(2) which gives me info about these
sched_get_priority_max() sched_get_priority_min()

If you read this and used SCHED_HPUX, with some fiddling, it would indicate that you can't use {1} above but you must use a value between:
Min pri: -256, max pri: -129

I needed to be root to use -129, or any other value.