# problems on same priority tasks

**URL:** <https://forums.freertos.org/t/problems-on-same-priority-tasks/1681>\
**Category:** Kernel\
**Created:** [March 1, 2008, 6:49am UTC](https://forums.freertos.org/t/problems-on-same-priority-tasks/1681 "2008-03-01T06:49:20Z")\
**Posts on this page:** 5\
**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:** [March 1, 2008, 6:49am UTC](https://forums.freertos.org/t/problems-on-same-priority-tasks/1681/1 "2008-03-01T06:49:20Z")

</div>

**[saravanan85](https://sourceforge.net/u/saravanan85/)** wrote on [Saturday, March 01, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/499f4ea0/#f83e):

Hi all,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I have working with i.MX27 multimedia application processor.I am using FreeRTOS v4.7.1 and IAR embedded workbench v5.11 for my project.I am newbie to the FreeRTOS.I have created simply 3 tasks and assign the priorities.there is no problem when tasks have different priotities.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; But if i assign the same priority for 2 or 3 tasks,it will point out last priority task only.if task 1 and 2 have same priority,it points 2nd task only or tasks 1&3 or 2&3 have same priority,it points 3rd task only.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I dont know what will happened on 2 or more tasks have the same priority.so anyone suggest idea for my problem.

regards,  
saravanan.r

---

<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:** [March 1, 2008, 1:24pm UTC](https://forums.freertos.org/t/problems-on-same-priority-tasks/1681/2 "2008-03-01T13:24:46Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Saturday, March 01, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/499f4ea0/#f83e/6d28):

Do you have configUSE\_PREEMPTION set to 1 in FreeRTOSConfig.h?

If so, can you create three very simple tasks (may that do nothing but flash an LED each, then sleep) that have a similar structure to your real tasks to see if these run as expected - and if not post the code for these simple tasks here.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 3, 2008, 7:46am UTC](https://forums.freertos.org/t/problems-on-same-priority-tasks/1681/3 "2008-03-03T07:46:21Z")

</div>

**[saravanan85](https://sourceforge.net/u/saravanan85/)** wrote on [Monday, March 03, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/499f4ea0/#f83e/be13):

Hi richardbarry,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thanks for your quick reply.Now i am currently working in IAR Embedded Workbench v5.11 simulator.I have no any hardware device.so i cant able to check in hardware device.I have write my piece of code here.

#include "FreeRTOS.h"  
#include "task.h"

#define TASK1\_PRIORITY&nbsp;&nbsp;&nbsp;&nbsp; ( tskIDLE\_PRIORITY + 2)  
#define TASK2\_PRIORITY&nbsp;&nbsp;&nbsp;&nbsp; ( tskIDLE\_PRIORITY + 3)  
#define TASK3\_PRIORITY&nbsp;&nbsp; ( tskIDLE\_PRIORITY + 4)

main()  
{  
&nbsp;&nbsp;&nbsp; xTaskCreate( TASK1,"CHECK", configMINIMAL\_STACK\_SIZE, NULL,TASK1\_PRIORITY,NULL);  
&nbsp;&nbsp;&nbsp; xTaskCreate( TASK2,"LCD",configMINIMAL\_STACK\_SIZE, NULL,TASK2\_PRIORITY, NULL);  
&nbsp;&nbsp;&nbsp; xTaskCreate( TASK3,"MSG", configMINIMAL\_STACK\_SIZE,NULL,TASK3\_PRIORITY, NULL);  
&nbsp;&nbsp;&nbsp; vTaskStartScheduler();  
&nbsp;&nbsp;&nbsp; for(;😉  
}  
static void TASK1( void \*pvParameters )  
{  
int i=0;  
for()  
{  
&nbsp;&nbsp; i++;  
&nbsp;&nbsp; -------task code here---------------  
}  
}

static void TASK2( void \*pvParameters )  
{  
int j=0;  
for()  
{  
&nbsp;&nbsp; j++;  
&nbsp;&nbsp; -------task code here---------------  
}  
}  
static void TASK3( void \*pvParameters )  
{  
int k=0;  
for()  
{  
&nbsp;&nbsp; k++;  
&nbsp;&nbsp; -------task code here---------------  
}  
}

Yes,i have configUSE\_PREEMPTION set to 1 in FreeRTOSConfig.h.If i have assign the same priorities for tasks 2&3 or 1&3,scheduler points k++(task3)only.it will go to j++(task2) or i++(task1)respectively, when i suspend the 3rd task only.what will happened if a one of the task has same priority.

Regards,  
saravanan.r

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 3, 2008, 8:35am UTC](https://forums.freertos.org/t/problems-on-same-priority-tasks/1681/4 "2008-03-03T08:35:14Z")

</div>

**[bkastel1](https://sourceforge.net/u/bkastel1/)** wrote on [Monday, March 03, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/499f4ea0/#f83e/be13/daa4):

Hello,

maybe it is just a typing mistake but your for() loop is missing ; - it should be for(;;){}. And also you should have a wait condition of somekind - maybe just a vTaskDelay(some\_ticks); . Otherwise your highest task will not do a context switch to a task of lower priority.

regards,

Borut

---

<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:** [March 3, 2008, 8:49am UTC](https://forums.freertos.org/t/problems-on-same-priority-tasks/1681/5 "2008-03-03T08:49:17Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, March 03, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/499f4ea0/#f83e/be13/f6c0):

The IAR simulator is a core only simulator.&nbsp; This means it does not simulate the timer and therefore the tick interrupt will not be executing.&nbsp; Without the tick interrupt you will never switch tasks unless you use a taskYIELD() statement - I’m not sure if the yielding works in the simulator but I would guess that it did.

Regards.
