setting thread priority


Threads inherit priority from its parent by default.
How can I assign different priority to a thread with function calls?

Here is the context:
I uses pthread_create to generate a network thread. I need it to run at low priority so that it won’t affects the main thread.

The function sched_setscheduler only works for processes?
procnto is not a function call.



pthread_attr_*() to set pthread_attr_t and pass it in pthread_create().


pthread_getschedparam()/pthread_setschedparam() after the thread is created

Thanks! I have tried it and am able to change the thread priority.

Unfortunately, it does not solve the problem I have.
Here is the problem:
I have a main thread running at the highest priority 255. I also have one network thread running at a low priority 50, using pthread_setschedparam.

If the other side of the network exits without noticing, the whole QNX system is stuck. I cannot interact with the main thread anymore, although the main thread has the highest priority.
This does not happen if the main thread runs at default priority. So the network codes do not have problems.

Where should I look for the cause?

Thanks again!


Other than the question of why you need to run at those incredibly high priorities (since nothing in the regular O/S runs anywhere near those numbers), my question would be, how do you know the main thread is stuck? Is it supposed to be printing to the screen?

How are you creating the threads? Is there any chance your suffering from priority inversion (where the network thread is holding up the main one when the other side dies)?

This is going to be hard to find because with everything running at those insane priorities, your not going to be able to easily debug it. You may have to lower the main thread to something like 40 and the network one to 39 (1 lower is fine) and then have a priority 41 console/Eclipse connection so you can get some CPU time to find out what’s going on.