Task with the same level

ulmus71 wrote on Sunday, October 09, 2011:

I cannot find it with clear explanation: e.g. i have many tasks with the same level/priority then….  are they started one by one every tick and after the last there is started first task and so on? What if one task longs longer then one or more tick period? Is there then task switch?

edwards3 wrote on Sunday, October 09, 2011:

Tasks that have the same priority and are in the ready state will run in turn, with a task switch on each tick interrupt (or task yield), but are not guaranteed to get the same amount of running time. For example, interrupts might take up some time.

richard_damon wrote on Sunday, October 09, 2011:

Basically what FreeRTOS does (when configured for preemption, and the schedule is not currently suspended) is on the Tick Interrupt, the current task Yields, which suspends the current task, and moves it to the end of it ready queue. It then schedules the task at the front of the highest ready queue with an available task. This will generally cause the tasks of a given priority to run is sequence. Ad Edwards says, this doesn’t mean they will all get equal time, not only due to interrupts, but if higher priority tasks unblock, they will take time from the current task. At a pathological extreme, one of the tasks could be checking the timer tick and just before the tick comes could start a higher priority task (that runs long enough to go past the timer tick), and I believe it will restart when the higher priority task finishes, perhaps starving other tasks at its level, or it could yield just before the timer tick, causing the next task in sequence to get short changed for it share of the tick. This is one reason while the idle task can be configured to yield or not. If it yields and there are two other tasks that share its priority, the one following the idle task will get short changed for time, while if it doesn’t yield, they all will be given full slots, but you are losing some available time.