Same priority tasks

Hi all,

I’m using freeRTOS v8 and I set:
configUSE_PREEMPTION 1
configUSE_TIME_SLICING 0

When I looked into the code I found this in xTaskIncrementTick():
if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )

Now imagine we have 2 tasks with the same priority. Task A is running a lengthy computation and task B is sleeping. When the sleep time of task B expires, it seems that it will wake up and then preempt task A. That’s what I deduce from the equal sign in the condition above.

What I’m trying to do is when 2 tasks with the same priority are ready to run we will start the first run it till the end of the task. the preemption that I want is only when there is a higher priority task or when there is an interrupt we will handle the interrupt and return to the task we left.

I assumed that by changing the condition above to:
if( pxTCB->uxPriority > pxCurrentTCB->uxPriority )

I will be able to do this but its doesn’t work…

Can you help me understand how the scheduler choose the next task to run when there are a few tasks with the highest priority in the ready state?

Thanks!

You are using an old version of code, and haven’t linked to the line you are referring to. Links in this reply relate to the last release.

If you have preemption turned on and time slicing turned off then:

So it looks like your edit would achieve your desired behaviour.