1
votes

Given - Thread id of a thread.
Requirement - Set Linux priority of the thread id.
Constraint - Cant use setpriority()

I have tried to use below

pthread_setschedprio(pthread_t thread, int prio);
pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param);

Both the above APIs use pthread_t as an argument. I am not able to construct (typecast) pthread_t from thread id. I understand converting this is not possible due to different types.

Is there a way to still accomplish this ?

1
From where do you get the thread ID?Florian Weimer

1 Answers

1
votes

Some aspects of the pthread_setschedprio interface are available for plain thread IDs with the sched_setparam function (declared in <thread.h>). The sched_setparam manual page says that the process is affected (which is the POSIX-mandated behavior), but on Linux, it's actually the thread of that ID.

Keep in mind that calling sched_setparam directly may break the behavior expected from PI mutexes and other synchronization primitives because the direct call does not perform the additional bookkeeping performed by the pthread_* functions.