Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

Fixed Running Order

Posted by Mathias Zenger on June 21, 2010
Hi,
My application is running on a AT32UC3A and basically has several tasks with different priorities. There are three tasks which should execute in a fixed order. All three tasks have the same priority and are calling vTaskDelayUntil() with the same delay of 10ms. I expected that the tasks would always execute in the same order as I had started them. However, task 2 and 3 sometimes seem to change the order while task one remains the frist to be executed. What could be the reasons for this change and how can I avoid it? Thanks for your advice!
Mathias

RE: Fixed Running Order

Posted by MEdwards on June 29, 2010
Tasks that have equal priority are not guaranteed to get an equal amount of CPU time. This is because asynchronous events (interrupts) can cause a context switch at any time. This is why the running order could potentially change.

If you want a fixed running order then you could control this manually by suspending and resuming tasks, running all the functionality in a single task, or using something like a semaphore.

RE: Fixed Running Order

Posted by raedbenz on July 11, 2010
Hello,
I wnat to double check something:
if u create task1, task2 and task3 using

xTaskCreate( vTaskCode1, "NAME1", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
xTaskCreate( vTaskCode2, "NAME2", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
xTaskCreate( vTaskCode3, "NAME3", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );

Does this mean initially (ignoring events at running time ) the task execution order will be as defined above?

Thanks

RE: Fixed Running Order

Posted by Richard Damon on July 11, 2010
If tasks need to run in a specific order, and that isn't being enforced by synchronizing operations (and delay isn't one of these) then the program is wrong.

If they are truly doing a set of sequential operations, it probably makes sense to make them 1 task , maybe with a central loop calling separate functions like:


void backtask(void* p){
while(1){
backtask1();
backtask2();
backtask3();
/* Maybe add the wait until here */
}
}


If there is some reason this won't work, than task1 needs to set a flag when it is done that task2 takes (and task2 sets a different flag for task3, and task3 another different flag for task1), then this will force the order to be as expected. If this only wants to be run periodically, then task1 after signaling task2, can waituntil before (or after) waiting for the flag from task3. It might be good to also see if it is running behind (which may be what is causing things to switch order).

RE: Fixed Running Order

Posted by raedbenz on July 11, 2010
hello richard,
thanks for the detailed reply. one more thing, according to my code above will the scheduler start scheduling task1 first then task2 etc.. ?
cheers

RE: Fixed Running Order

Posted by Richard Damon on July 11, 2010
Richard Barry would probably know, otherwise it would take a detailed analysis of how xTaskCreate works to see what order things end up on the ready list (i.e. do new tasks end up at the front or back of the ready list for their priority). One warning, since that order isn't documented, it can not be counted on, and even if, say, task1 gets scheduled first, you have no idea how much time it will get (without a significant whole program analysis), as it may get started with just a few clock cycles before the next timer tick, so it may look to the tasks like task2 started first. This is why if it matters, your program has an error.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists