in a non preemptive system, after an ISR finishes execution, will the interrupted task continue execution even if a higher priority task was activated?
-
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Apr 07 '22 at 01:47
-
You have made a statement rather than asking a question (adding a ? at the end does not really make it a question; just grammatically confused ). What makes you think that might be true? – Clifford Apr 07 '22 at 06:49
-
@Clifford I am sorry for that I copied the statement of the question which its answer was either the statement is true or false. I edited the question now – Muhammad Ali Apr 07 '22 at 14:20
-
The answer may be RTOS specific. Is there a specific RTOS in your mind? FreeRTOS maybe? – Tagli Apr 07 '22 at 15:04
-
@Tagli but FreeRTOS (and RTOS in general) is pre-emptive, so presumably not that. – Clifford Apr 07 '22 at 18:58
-
Presumably this refers to cooperative multitasking, where a task must explicitly yield for a scheduling decision to be made. Draw your on conclusion. – Clifford Apr 07 '22 at 18:59
-
@Clifford , FreeRTOS is pre-emptive by default, but it can also be configured to be **non** pre-emptive. – Tagli Apr 07 '22 at 20:30
1 Answers
This answer is specific to FreeRTOS, and may not be relevant to other RTOS'es.
FreeRTOS is preemptive by default. However, it can also be configured to be non-preemptive by the config option in FreeRTOSConfig.h
#define configUSE_PREEMPTION 0
Normally, a return from ISR does not trigger a context switch. But in preemptive systems it's often desirable, so in most FreeRTOS examples, you see portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
at the end of the ISR, which triggers a context switch if xHigherPriorityTaskWoken
is pdTRUE
.
xHigherPriorityTaskWoken
is initialized to pdFALSE
at the start of the ISR (manually by the user), and operations which can cause a context switch, such as vTaskNotifyGiveFromISR()
, xQueueSendToBackFromISR()
etc. , take it as an argument and set it to pdTRUE
if a context switch is required after the system call.
In a non-preemptive configuration, you simply pass NULL
to such system calls instead of xHigherPriorityTaskWoken
, and do not call portYIELD_FROM_ISR()
at the end of the ISR. In this case, even if a higher priority task is awakened by the ISR, execution returns to the currently running task and remains there until this task yields or makes a blocking system call.
You may mix ISR yield mechanism with preemption method. For example, you can force a context switch (preemption) from ISR even when configUSE_PREEMPTION
is 0, but this may cause problems if the interrupted/preempted task doesn't expect it to happen, so I don't recommend it.

- 2,412
- 2
- 11
- 14