Preemption in equal priority task by a higher priority task

I have four task, TASK_A have higher priority, TASK_B1, TASK_B2 and TASK_B3 have same priority.

FreeRTOS configuration is
#define configUSE_PREEMPTION (1)
#define configUSE_TIME_SLICING (0)

when All equal priority tasks are in ready state but when TASK_A Preempts a task, while returning from TASK_A it causes task switch in equal priority. suppose TASK_B1 is running and TASK_A Preempts it then after completing TASK_A it returns in TASK_B2, again TASK_A preempts TASK_B2 and then after completing TASK_A it gives control to TASK_B3.

Is this behavior is as expected?
If yes, then how this will behave when two or more equal priority tasks becomes ready?
which one will be running after switching from higher priority task?
What is the Algorithm here?

Please explain, thanks.

Yes this is the expected behavior.

No sure I understand this part as in your example there were there tasks in the ready state.

As FreeRTOS runs on small microcontrollers the algorithm is very simple. FreeRTOS will always run the highest priority task that is able to run, and if there are tasks of equal priority then the tasks will run in turn (the one that has been waiting the longest being the first to execute) - but tasks are not guaranteed to get the same amount of CPU time.

I would recommend reading through the book:

1 Like

Thanks for reply,

Here I mean, if TASK_B1 and TASK_B2 are in blocked state and both becomes ready by TASK_A then which task will be served next? Is these depends in which sequence tasks becomes ready.

Yes - whichever is moved to the ready state first will be the one to run first. This is what I was referring to with this statement: