Behavior of critical section inside a task
Posted by aamir mahmood
on June 12, 2009
I have a question on the behavior of critical section procession (portENTER_CRITICAL( ) and portEXIT_CRITICAL( )). As I understood all the interrupts other that SWI are disabled as the code execution enters into the critical section.
Assuming a taskA with priority 1 is allocated with its time slice by the scheduler and taskA have just entered into the critical section of the code. While the code inside the critical section is executing, the taskA time slice expires and another taskB with higher priority 2 goes into the ready state. The question is, will critical section be able protect the taskA from being preempted by taskB? If not what could be done to prevent a higher priority task from preempting a lower priority task which is doing something critical.
RE: Behavior of critical section inside a task
Posted by Richard Damon
on June 12, 2009
When you enter the critical section, the interrupts (or at least those involved that interact with scheduling) are disabled. When the time slice ends, the hardware will set the request for the timer interrupt, but the interrupt will not actually occur (since it is disabled) so nothing will cause the task switch. When the critical section ends, the interrupt will occur, and taskB will get switched in, but none of this happens until the critical section is over.
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.