Quality RTOS & Embedded Software

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




Loading

Order of thread execution?

Posted by kuku2010 on August 27, 2012
3 threads: A @ priority 3, B @2, C @1, one interrupt D, system tick is 1ms

All threads takes only a small fraction of time to run most time.

A ran for a fraction of ms and wait for the semaphore to be given by D, so the next thread will run
B ran for a fraction of ms and use vTaskDelay(1) to allow the next thread to run
C ran for a fraction of ms and called vTaskDelay(1)

At this point, 1ms hasn't passed yet, so will the system enter some idle state until the next tick? If so, is there a way to wake up a specific thread? For example, wake up B and it runs until the next tick, which will be A's turn again.

(Still no system tick) If D gives the semaphore, will A resume immediately? If so, when the next system tick occurs, I assume A continue since it has the highest priority

Thanks for your time!


RE: Order of thread execution?

Posted by Dave on August 27, 2012
“At this point, 1ms hasn't passed yet, so will the system enter some idle state until the next tick?”


The idle task will run at priority 0.

“For example, wake up B and it runs until the next tick, which will be A's turn again.”


Your code has told B to wait for 1 tick, so that is what it will do. You could run B at priority 0 too, in which case it will share processing with the idle task when A and C are not running. Setting configIDLE_SHOULD_YIELD to 1 in FreeRTOSConfig.h makes the idle task always yield to B straight away if B is not blocked. Alternatively you can make B block on a semaphore instead of vTaskDelay(1) and give the semaphore from the idle hook function but that would seem like overkill.

“If D gives the semaphore, will A resume immediately?”


Yes, if that is what you told it to do, of course. The port you are using will have a YIELD_FROM_ISR or END_SWITCHING_ISR macro to ensure it happens. Both macros do the same thing, different ports just use different names for some reason. Look at the examples that come with your port. http://www.freertos.org/a00090.html

“If so, when the next system tick occurs, I assume A continue since it has the highest priority”


Yes. The highest priority task that is not blocked or suspended will always run, and time slice with other tasks that have the same priority and are also not blocked if there are any.

RE: Order of thread execution?

Posted by kuku2010 on August 28, 2012
"Setting configIDLE_SHOULD_YIELD to 1 ", do you mean "Setting configIDLE_SHOULD_YIELD to 2", since B has priority of 2?

RE: Order of thread execution?

Posted by Dave on August 28, 2012
“Setting configIDLE_SHOULD_YIELD to 1 ", do you mean "Setting configIDLE_SHOULD_YIELD to 2", since B has priority of 2”


No, configIDLE_SHOULD_YIELD is binary, 1 or 0. I mentioned it in context of running the other task at priority 0 (idle priority). Look it up on http://www.freertos.org/a00110.html


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




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

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

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

OpenRTOS and SafeRTOS