Change thread priority

Hi friends,

I have three threads in my RTOS. When I define priorities for all threads identically, there is no problem and all the three threads run normally. But when I change the priority of one of threads (to above the priority of other two) the other two threads do not execute. Is there any property that I must change or define to be able to change the priority? Or sth. else?

My threads' definitions in normal case:
osThreadDef (job1, osPriorityAboveNormal, 1, 0);
osThreadDef (job2, osPriorityAboveNormal, 1, 0);
osThreadDef (job3, osPriorityAboveNormal, 1, 0);

My threads' definitions when have problem:
osThreadDef (job1, osPriorityAboveNormal, 1, 0);
osThreadDef (job2, osPriorityAboveNormal, 1, 0);
osThreadDef (job3, osPriorityHigh, 1, 0);

p.s.: I have tried other priorities like osPriorityAboveNormal and ..., but the problem persists.

Your prompt response would be greatly appreciated,
Elham

Parents
  • In an RTOS, a lower priority thread must be preempted if a higher priority thread is ready to run. Your highest priority thread seems to always be available to run (it is not "waiting" for some event to happen) so it is the one running. There behavior is expected and required by an RTOS.

    threads running in an RTOS are often "doing nothing" except waiting for an even to happen. When the event happens, the thread is put into the READY queue and will be given the processor based on thread priority (Highest priority thread that is ready to run will be given the CPU)

Reply
  • In an RTOS, a lower priority thread must be preempted if a higher priority thread is ready to run. Your highest priority thread seems to always be available to run (it is not "waiting" for some event to happen) so it is the one running. There behavior is expected and required by an RTOS.

    threads running in an RTOS are often "doing nothing" except waiting for an even to happen. When the event happens, the thread is put into the READY queue and will be given the processor based on thread priority (Highest priority thread that is ready to run will be given the CPU)

Children
More questions in this forum