Same priority tasks are not executing cooperatively using yield

Hi Guys,

I have 4 tasks and all the tasks are of equal priority. Each task increments its respective counter and performs yield.

void  thread_0(void)
{
    while(1)
    {        
        taskYIELD();

        /* Increment this thread's counter.  */
        thread_0_counter++;
    }
}

Similar to this all other tasks are created with their respective counters. The variables are global and configUSE_PREEMPTION is set to 1.

The goal of the application is to see whether the tasks are performing cooperatively.

when I set a breakpoint after 2s(arbitrary), my expected output is that all the counters should have the same value. but I am seeing a difference in the counter values.
image

if configUSE_PREEMPTION is set to 0 and the application is run, my expected behaviour is happening. ie. the counter values are same.

I understand that configUSE_PREEMPTION set to 0 causes cooperative scheduling which inturn is giving my expected result, but Why is configUSE_PREEMPTION set to 1 (priority preemptive scheduling) with equal priority tasks, not giving the same result? what is happening internally? kindly explain this behaviour.

Thanks.

When preemption is enabled, then every time a tick interrupt occurs, effectively what ever task is at that moment current yields, even if just an instruction or two previously it just got switched to. This will cause the slightly unequal allocation of time.