Task priority belowNormal

I had a funny problem. I was running two tasks. Task1 with osPriorityNormal, Task2 with osPriorityBelowNormal.

Task1 was running in a tight loop, checking whether a character is available in the input queue.

It seemed to as if Task2 was never executed. Could that be?

FreeRTOS v2 on an STM32F103C8T6

Yes, that is the intended behavior. The scheduler always runs the highest priority ready task. So, if your higher priority task never blocks, other lower priority tasks will starve. The tasks chapter in this book is good resource to learn these concepts - https://www.freertos.org/fr-content-src/uploads/2018/07/161204_Mastering_the_FreeRTOS_Real_Time_Kernel-A_Hands-On_Tutorial_Guide.pdf

Thanks. You say "So, if your higher priority task never blocks, other lower priority tasks will starve. "

Do you really mean that or is it a typo? You mean, when the higher priority always blocks (?)

To my understanding, Gaurav’s wording is correct.

No - I really mean what I typed. To repeat, the higher priority task needs to block to allow other lower priority tasks to run.

To my understanding, blocking is that:

for(;;)

While releasing is

for(;;) {
   osDelay(10);
}

Gaurav (I believe) and I interpret “blocking” as “yielding the CPU by waiting for an external event,” that is, being blocked instead of blocking (starving) other threads of execution.

I can see that the term “block” can be a source of confusion here when being looked at active instead of passive.

At a high level, a task has the following states -

  1. Running - The task is executing and actively using CPU.
  2. Ready - The task is ready to run but not running as the scheduler has currently selected some other task to run. The scheduler will pick it up when it becomes the highest priority ready task.
  3. Blocked - The task cannot run because it is waiting for an event (one such event is a delay expire event which happens when the time passed to osDelay expires). The scheduler can not pick up this task until it becomes Ready.

I’d again recommend the book I mentioned above.

Thanks. Sorry for my confusion :slight_smile: