FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [June 2010 Threads] Fixed Running OrderPosted 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 OrderPosted 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 OrderPosted 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 OrderPosted 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 OrderPosted 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 OrderPosted 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.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|