I have a single threaded application. If i use below code, i get sched_setscheduler(): Operation not permitted
.
struct sched_param param;
param.sched_priority = 1;
if (sched_setscheduler(getpid(), SCHED_RR, ¶m))
printf(stderr, "sched_setscheduler(): %s\n", strerror(errno));
But, if i use pthread api such as below, i dont get an error. What is the difference between the two for a single threaded application and is the below function really changing the scheduler and priority or am i missing some error handling?
void assignRRPriority(int tPriority)
{
int policy;
struct sched_param param;
pthread_getschedparam(pthread_self(), &policy, ¶m);
param.sched_priority = tPriority;
if(pthread_setschedparam(pthread_self(), SCHED_RR, ¶m))
printf("error while setting thread priority to %d", tPriority);
}
The error may be caused by a limit set on realtime priority (ulimit -r
to check, ulimit -r 99
to allow 1-99 priorities). As of pthread_setschedparam
being successful: if you compiled without -pthread
option, this function is just a stub, like some other pthread functions. With -pthread
option, the results should be identical (strace
shows that the same system call is used).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With