# Processing time between tasks with the same priority

**URL:** <https://forums.freertos.org/t/processing-time-between-tasks-with-the-same-priority/6571>\
**Category:** Kernel\
**Created:** [May 9, 2017, 10:34am UTC](https://forums.freertos.org/t/processing-time-between-tasks-with-the-same-priority/6571 "2017-05-09T10:34:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 9, 2017, 10:34am UTC](https://forums.freertos.org/t/processing-time-between-tasks-with-the-same-priority/6571/1 "2017-05-09T10:34:32Z")

</div>

**[orifai01](https://sourceforge.net/u/orifai01/)** wrote on [Tuesday, May 09, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/30fbd897/#b8b3):

Hi,  
I wonder how the scheduler decides between two tasks with the same priority, when configUSE\_PREEMPTION equals to 1 and configUSE\_TIME\_SLICING equals to 0 (i.e. a context switch should not occur on a tick interrupt).  
Thank you in advanced.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [May 9, 2017, 2:11pm UTC](https://forums.freertos.org/t/processing-time-between-tasks-with-the-same-priority/6571/2 "2017-05-09T14:11:26Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, May 09, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/30fbd897/#b8b3/ea73):

…the same way it does when configUSE\_PREEMPTION is 1, it will always  
choose the task of that priority that has been waiting the longest.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [May 9, 2017, 2:11pm UTC](https://forums.freertos.org/t/processing-time-between-tasks-with-the-same-priority/6571/3 "2017-05-09T14:11:54Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, May 09, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/30fbd897/#b8b3/1988):

Sorry, I meant the same way it does when configUSE\_TIME\_SLICING is 1.

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [May 9, 2017, 4:09pm UTC](https://forums.freertos.org/t/processing-time-between-tasks-with-the-same-priority/6571/4 "2017-05-09T16:09:09Z")

</div>

**[heinbali01](https://sourceforge.net/u/heinbali01/)** wrote on [Tuesday, May 09, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/30fbd897/#26d9):

And so :

> the [way the] scheduler decides between two tasks with the same priority

is

> …the same way it does when configUSE\_TIME\_SLICING is 1, it will always  
> choose the task of that priority that has been waiting the longest.

FreeRTOS has a principle of “ **fairness** ”:

● The runnable task with the highest priority will be selected  
● If the are more runnable tasks with the highest priority, the one which is waiting the longest will go first

( where “runnable” means “ready to run”, enlisted in the `pxReadyTasksLists[]` )

As you probably know, `configUSE_TIME_SLICING` needs `configUSE_PREEMPTION` to be effective.

With time-slicing enabled, the clock-tick will force a task-switch, in case there are more runnable tasks of the same priority.  
Without time-slicing enabled, a task must yield explicitly in order to switch to the next same priority-task.
