# FreeRTOS Round Robin

**URL:** <https://forums.freertos.org/t/freertos-round-robin/1486>\
**Category:** Kernel\
**Created:** [December 7, 2015, 4:54pm UTC](https://forums.freertos.org/t/freertos-round-robin/1486 "2015-12-07T16:54:00Z")\
**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:** [December 7, 2015, 4:54pm UTC](https://forums.freertos.org/t/freertos-round-robin/1486/1 "2015-12-07T16:54:00Z")

</div>

**[cdb1702](https://sourceforge.net/u/cdb1702/)** wrote on [Monday, December 07, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/402712c8/#60e4):

What are ,in the source code of FreeRTOS.the functions that make the round robin in the case of tasks with the same priority?  
The following example is taken from USING THE FREERTOS REAL TIME KERNEL A Practical Guide  
Richard Barry  
void vTaskFunction( void \*pvParameters )  
{  
char _pcTaskName;  
volatile unsigned long ul;  
/_ The string to print out is passed in via the parameter. Cast this to a  
character pointer. _/  
pcTaskName = ( char \* ) pvParameters;  
/_ As per most tasks, this task is implemented in an infinite loop. _/  
for( ;; )  
{  
/_ Print out the name of this task. _/  
vPrintString( pcTaskName );  
/_ Delay for a period. _/  
for( ul = 0; ul \< mainDELAY\_LOOP\_COUNT; ul++ )  
{  
/_ This loop is just a very crude delay implementation. There is  
nothing to do in here. Later exercises will replace this crude  
loop with a proper delay/sleep function. _/  
}  
}  
}  
/_ Define the strings that will be passed in as the task parameters. These are  
defined const and not on the stack to ensure they remain valid when the tasks are  
executing. _/  
static const char pcTextForTask1 = “Task 1 is running\r\n”;  
static const char pcTextForTask2 = “Task 2 is running\t\n”;  
int main( void )  
{  
/ Create one of the two tasks. /  
xTaskCreate( vTaskFunction, / Pointer to the function that implements  
the task. /  
“Task 1”, / Text name for the task. This is to  
facilitate debugging only. /  
1000, / Stack depth - most small microcontrollers  
will use much less stack than this. /  
(void)pcTextForTask1, / Pass the text to be printed into the task  
using the task parameter. /  
1, / This task will run at priority 1. /  
NULL ); / We are not using the task handle. /  
/ Create the other task in exactly the same way. Note this time that multiple  
tasks are being created from the SAME task implementation (vTaskFunction). Only  
the value passed in the parameter is different. Two instances of the same  
task are being created. /  
xTaskCreate( vTaskFunction, “Task 2”, 1000, (void)pcTextForTask2, 1, NULL );  
/_ Start the scheduler so our tasks start executing. _/  
vTaskStartScheduler();  
/_ If all is well then main() will never reach here as the scheduler will  
now be running the tasks. If main() does reach here then it is likely that  
there was insufficient heap memory available for the idle task to be created.  
CHAPTER 5 provides more information on memory management. \*/  
for( ;; );  
}

---

<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:** [December 7, 2015, 6:40pm UTC](https://forums.freertos.org/t/freertos-round-robin/1486/2 "2015-12-07T18:40:18Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, December 07, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/402712c8/#441f):

Search for

```
#if ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) )
```

in this file

[https://sourceforge.net/p/freertos/code/HEAD/tree/trunk/FreeRTOS/Source/tasks.c#l2091](https://sourceforge.net/p/freertos/code/HEAD/tree/trunk/FreeRTOS/Source/tasks.c#l2091)

to see the souce lines.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 9, 2015, 8:51am UTC](https://forums.freertos.org/t/freertos-round-robin/1486/3 "2015-12-09T08:51:32Z")

</div>

**[cdb1702](https://sourceforge.net/u/cdb1702/)** wrote on [Wednesday, December 09, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/402712c8/#862b):

Thank you  
Carlo De Bonis

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 9, 2015, 9:39am UTC](https://forums.freertos.org/t/freertos-round-robin/1486/4 "2015-12-09T09:39:15Z")

</div>

**[cdb1702](https://sourceforge.net/u/cdb1702/)** wrote on [Wednesday, December 09, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/402712c8/#d52e):

I am using FreeRTOS V7.1.1 - Copyright © 2012 Real Time Engineers Ltd. and in this version there is not the funnction  
BaseType\_t xTaskIncrementTick( void )  
nor is this the definition of configUSE\_TIME\_SLICING  
but the example taken from USING THE FREERTOS REAL TIME KERNEL A Practical Guide it is earlier
