Behavior of critical section inside a task

Hi, 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. Best regards, Aamir  

Behavior of critical section inside a task

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.