# Same priority task

**URL:** <https://forums.freertos.org/t/same-priority-task/10038>\
**Category:** Kernel\
**Created:** [June 14, 2020, 8:08pm UTC](https://forums.freertos.org/t/same-priority-task/10038 "2020-06-14T20:08:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Take](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@Take](https://forums.freertos.org/u/Take)\
**Post date:** [June 14, 2020, 8:08pm UTC](https://forums.freertos.org/t/same-priority-task/10038/1 "2020-06-14T20:08:13Z")

</div>

Hi, I just started to learn about freertos and i have a question about task management.

I made two tasks in following the code and assuming that two functions will be called one at a time when tick interrupt.  
But result is different, taks2 was never called

The code is following…

```auto
xTaskCreate(vContinuousProcessingTask, "Task1", configMINIMAL_STACK_SIZE + 100,pcTextForTask1,1, NULL)

xTaskCreate(vContinuousProcessingTask, "Task2", configMINIMAL_STACK_SIZE + 100,pcTextForTask2,1, NULL)

And function itself is just calling printf in the loop...

static void vContinuousProcessingTask(void *text)
{
	for(;;)
	{
		PRINTF(text);
	}
}

```

Task configuration I set is following

```auto
#define configUSE_PREEMPTION 0
#define configUSE_TIME_SLICING 1

```

I think i missed something, but i cannot figure out.  
So, please tell me what it is.

Best regards,  
Take

---

<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:** [June 14, 2020, 8:11pm UTC](https://forums.freertos.org/t/same-priority-task/10038/2 "2020-06-14T20:11:51Z")

</div>

What is PRINTF() doing? Try replacing the print statement with a simple increment of a variable, using a different variable in each task. What happens then? Do both variables increment or just one?

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [June 14, 2020, 10:15pm UTC](https://forums.freertos.org/t/same-priority-task/10038/3 "2020-06-14T22:15:41Z")

</div>

One comment, you have configUSE\_PREEMPTION = 0, which means that the only point when any task switch will occur, is on calls to FreeRTOS operations. Neither of your tasks seem to do that (unless it is buried in PRINTF).

The configUSE\_TIME\_SLICING means that on the tick interrupt, the other task will become ahead of the current on in priority, but until an opportunity arrises to perform a task switch, nothing will happen. While configUSE\_PREEMPTION = 0 does make some program tasks easier because you don’t need to worry about race conditions as much, it does mean you need to worry about providing for opportunity for a task switch or they might not happen, which can make latency promises a lot harder to make.

---

<div class="post-metadata">

**Author:** ![Take](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@Take](https://forums.freertos.org/u/Take)\
**Post date:** [June 15, 2020, 6:23pm UTC](https://forums.freertos.org/t/same-priority-task/10038/4 "2020-06-15T18:23:00Z")

</div>

Thank you for your reply.  
I thought task was switched automatically when tick event occurs.

Thanks again,  
take

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [June 15, 2020, 8:15pm UTC](https://forums.freertos.org/t/same-priority-task/10038/5 "2020-06-15T20:15:51Z")

</div>

It does, UNLESS you have explicitly disabled that by turning off preemption. That option changes FreeRTOS from a preemptive Real Time system into a cooperative Real Time System.

My suggestion, don’t turn off preemption unless you have a real need to do so.
