# Tasks not running in priority order

**URL:** <https://forums.freertos.org/t/tasks-not-running-in-priority-order/22763>\
**Category:** Kernel\
**Created:** [March 18, 2025, 1:14pm UTC](https://forums.freertos.org/t/tasks-not-running-in-priority-order/22763 "2025-03-18T13:14:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nielsenni](https://avatars.discourse-cdn.com/v4/letter/n/c4cdca/32.png) [@nielsenni](https://forums.freertos.org/u/nielsenni)\
**Post date:** [March 18, 2025, 1:14pm UTC](https://forums.freertos.org/t/tasks-not-running-in-priority-order/22763/1 "2025-03-18T13:14:35Z")

</div>

Hello all,

I have come across a weird issue where it looks like FreeRTOS is letting lower priority tasks to run over a higher priority one. Let me try to explain the specifics of this scenario.

There are 3 tasks at 3 different priorities (low, medium, and high) and 2 ISRs (same priority) in play here. Here is the order of events.

1. ISR A runs and signals tasks medium and low to run.
2. ISR B runs and signals high task to run.
3. Task Medium executes to completion
4. Task low executes to completion.
5. Task high executes

I would expect that task high runs first since it has the highest priority. configUSE\_PREEMPTION is enabled. I looked for a priority inversion case where task high is locked on a resource that low or medium is using but did not find that scenario. I do not have tracealyzer working at the moment (hoping to get that going soon). Any ideas on what is happening here is appreciated. Thanks!

FreeRTOS version 10.5.1  
Running on stm32mp257

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [March 18, 2025, 4:03pm UTC](https://forums.freertos.org/t/tasks-not-running-in-priority-order/22763/2 "2025-03-18T16:03:54Z")

</div>

First, with preemption enabled, you still need the ISR to trigger the rescheduling to make it happen right away, normally with some code that tests the “was woken” flag from the signalling call.

Second, you are remember that “low priority” for tasks is smaller numbers, (0 is the idle task priority) and higher values are higher priority?

If anything, when the medium task completes and reschedules, the system should take the High Priority task over the low, unless something has corrupted memory.

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [March 18, 2025, 4:15pm UTC](https://forums.freertos.org/t/tasks-not-running-in-priority-order/22763/3 "2025-03-18T16:15:29Z")

</div>

> [@nielsenni](#):
>
> I looked for a priority inversion case where task high is locked on a resource that low or medium is using but did not find that scenario.

Just to rule out an application bug, you can reduce the task definitions to minimum like toggling an LED or incrementing a variable and see if you still observe the same issue.

Here are couple of other things to check:

- Is tick interrupt firing and tick count incrementing?
- Did you use `portYIELD_FROM_ISR`in your ISR?

---

<div class="post-metadata">

**Author:** ![nielsenni](https://avatars.discourse-cdn.com/v4/letter/n/c4cdca/32.png) [@nielsenni](https://forums.freertos.org/u/nielsenni)\
**Post date:** [March 18, 2025, 4:21pm UTC](https://forums.freertos.org/t/tasks-not-running-in-priority-order/22763/4 "2025-03-18T16:21:34Z")

</div>

In the ISR it calls portYIELD\_FROM\_ISR() so it should trigger a context switch right away. Yes, I am aware that a higher priority task is a greater number and double and triple checked priority values of these tasks. Something weird is happening, maybe corrupted memory? Is there a way to tell if that is happening?

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [March 19, 2025, 5:23am UTC](https://forums.freertos.org/t/tasks-not-running-in-priority-order/22763/5 "2025-03-19T05:23:34Z")

</div>

> [@nielsenni](#):
>
> FreeRTOS version 10.5.1

Have you defined configASSERT? Can you try the latest main code?

---

<div class="post-metadata">

**Author:** ![bhoomrs](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/bhoomrs/32/5089_2.png) [@bhoomrs](https://forums.freertos.org/u/bhoomrs)\
**Post date:** [March 19, 2025, 9:03am UTC](https://forums.freertos.org/t/tasks-not-running-in-priority-order/22763/6 "2025-03-19T09:03:36Z")

</div>

If you suspect memory corruption, enable `configCHECK_FOR_STACK_OVERFLOW` according to [the listed methods here](https://www.freertos.org/Documentation/02-Kernel/02-Kernel-features/09-Memory-management/02-Stack-usage-and-stack-overflow-checking), and implement the`vApplicationStackOverflowHook()` function. This hook lets you catch and handle stack overflows, such as logging an error or halting the system.

Besides `configUSE_PREEMPTION`, other [configurations](https://www.freertos.org/Documentation/02-Kernel/03-Supported-devices/02-Customization) or [hooks](https://www.freertos.org/Documentation/02-Kernel/02-Kernel-features/12-Hook-functions)—such as the idle hook (`vApplicationIdleHook()`), tick hook (`vApplicationTickHook()`), or any custom code that alters the scheduler’s behavior—might interfere with normal operation. If any of these hooks are custom-defined in your application, can you try disabling them temporarily and running the system again to check for changes?

---

<div class="post-metadata">

**Author:** ![nielsenni](https://avatars.discourse-cdn.com/v4/letter/n/c4cdca/32.png) [@nielsenni](https://forums.freertos.org/u/nielsenni)\
**Post date:** [April 14, 2025, 7:52pm UTC](https://forums.freertos.org/t/tasks-not-running-in-priority-order/22763/7 "2025-04-14T19:52:05Z")

</div>

After some more investigation I found that out that the configTIMER\_TASK\_PRIORITY was set to 2. Increasing the priority to be the highest in the system got rid of this issue. It looks like that when setting an event from an ISR, it goes through the Timer Service task that is set to priority configTIMER\_TASK\_PRIORITY. Having it set so low caused it not to wake up to tell the higher priority thread to run when any task above a priority of 2 was running. Not sure why it defaults so low considering how important this Timer service task is.

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [April 14, 2025, 9:04pm UTC](https://forums.freertos.org/t/tasks-not-running-in-priority-order/22763/8 "2025-04-14T21:04:18Z")

</div>

One thing to point out is that you said you signaled “tasks”, which would normally imply using the direct-to-task notifications, which happen directly. Possibly it might mean signalling a semaphore that a task is waiting on, which also would happen directly.

It seems you were signaling an EventGroup, which is a much more heavy operation, because it might trigger multiple tasks to become ready, which is why it is deferred to the task level using the timer/service task.

I don’t know where you got your “default” value for that task, but yes, it is normally set to be the highest priority task, or at least close to that level.
