Quality RTOS & Embedded Software

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


Loading

Nested Critical Region

Posted by jackson on October 18, 2007
Will it be a problem when a task(A) yield from within the function vTaskPrioritySet()?(also many other functions such as xQueueSend...)that have the code structure

taskENTER_CRITICAL();
{
...
taskYIELD();
}
taskEXIT_CRITICAL();

and if the succeding task(B) also has a code
taskENTER_CRITICAL();
{
...
}
taskEXIT_CRITICAL();

From the Source code (ARM IAR port)

void vPortEnterCritical( void ) //taskENTER_CRITICAL()
{
__disable_interrupt();
ulCriticalNesting++;
}

void vPortExitCritical( void ) //taskEXIT_CRITICAL()
{
if( ulCriticalNesting > portNO_CRITICAL_NESTING ) //(>0)
{
ulCriticalNesting--;
if( ulCriticalNesting == portNO_CRITICAL_NESTING ) // == 0
{
__enable_interrupt();
}
}
}

My question is, will the interrupt still be disabled after task B leave the critical region ? If yes then it certainly not meet our desire.
Do i miss something ?

RE: Nested Critical Region

Posted by Richard on October 18, 2007
I need to write an FAQ on this one :o)

No it is not a problem for the kernel to switch tasks from within a critical section - in fact the scheduler locking mechanism relies on the ability to do this.

Each task maintains its own interrupt state. Therefore task A may enter a critical section, then yield to task B. When task A starts executing again it will do so from within the critical section, so interrupts will again be disabled. Task B may or may not have interrupts enabled, it depends on the interrupt status when task B yielded, so interrupts will not necessarily be disabled between when task A stops executing and subsequently starts executing again.

Regards.

RE: Nested Critical Region

Posted by Dave on October 18, 2007
>Each task maintains its own interrupt state

and each task saves its uxCriticalNesting value as part of its context.

RE: Nested Critical Region

Posted by jackson on October 18, 2007
What i mean is task B never expect it will cause the interrupt disabled after leave the critical section.

RE: Nested Critical Region

Posted by jackson on October 18, 2007
Thanks for your explanation !

RE: Nested Critical Region

Posted by Dave on October 18, 2007
I don't understand what you mean here. As far as TaskB is concerned it is the only task in the system. It does not know or care what TaskA is doing. It always has the interrupt state as it expects it to have. If its in a critical region then it expects to have interrupts diabled. If its out of a critical region then it expects to have interrupts enabled. This is always the case and is not dependent on when it or any other task yields. Critical sections can nest quite happily so the critical section will only be exited when the same number of calls are made to portEXIT_CRITICAL as were already made to portENTER_CRITICAL.


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


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

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

Xilinx Microblaze and Zynq partner