# Higher priority task to be woken

**URL:** <https://forums.freertos.org/t/higher-priority-task-to-be-woken/12793>\
**Category:** Kernel\
**Created:** [June 7, 2021, 12:26am UTC](https://forums.freertos.org/t/higher-priority-task-to-be-woken/12793 "2021-06-07T00:26:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rik001](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@Rik001](https://forums.freertos.org/u/Rik001)\
**Post date:** [June 7, 2021, 12:26am UTC](https://forums.freertos.org/t/higher-priority-task-to-be-woken/12793/1 "2021-06-07T00:26:27Z")

</div>

Hi,  
looking at this API sample code:

```
void vANInterruptHandler( void )
{
    BaseType_t xHigherPriorityTaskWoken;
    uint32_t ulStatusRegister;

    ulStatusRegister = ulReadPeripheralInterruptStatus();

    vClearPeripheralInterruptStatus( ulStatusRegister );

    xHigherPriorityTaskWoken = pdFALSE;

    xTaskNotifyIndexedFromISR( xHandlingTask,
                               0,
                               ulStatusRegister,
                               eSetBits,
                               &xHigherPriorityTaskWoken );

    /* Force a context switch if xHigherPriorityTaskWoken is now set to pdTRUE.
    The macro used to do this is dependent on the port and may be called
    portEND_SWITCHING_ISR. */
    portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}

```

If xHandlingTask is at priority 2 and there are other tasks at priority 1 and 3, which one will be immediately executed? xHandlingTask at priority 2 because the ISR just sent the notification to it or 3 if it was its turn?

What if the ISR was called in the middle of a task at priority 3, after the ISR, will the control go back to that priority 3 task until it is completed or to xHandlingTask (priority 2) because the ISR sent a notify and yielded from an ISR?

Thank you

---

<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:** [June 7, 2021, 1:01am UTC](https://forums.freertos.org/t/higher-priority-task-to-be-woken/12793/2 "2021-06-07T01:01:53Z")

</div>

The FreeRTOS schedule will ALWAYS chose the higher priority ready task, always.

If you interrupted a priority 3 task, and woke a priority 2 task, HigherPriorityTaskWoken would not be set, as there is no need to run the schedule, and if you did, it would still chose a Priority 3 ready task.

portYIELD\_FROM\_ISR just runs the scheduler, so the scheduler will still see that the priority 3 task was ready.

This is JUST like if the priority 3 task did a taskYIELD, that will check if another priority 3 task wants time and switch to it, but it will NOT switch to a priority 2 task.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [June 7, 2021, 1:15am UTC](https://forums.freertos.org/t/higher-priority-task-to-be-woken/12793/3 "2021-06-07T01:15:10Z")

</div>

Highly recommend reading the free to download book - think it will answer most of your questions.

---

<div class="post-metadata">

**Author:** ![Rik001](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@Rik001](https://forums.freertos.org/u/Rik001)\
**Post date:** [June 7, 2021, 11:12pm UTC](https://forums.freertos.org/t/higher-priority-task-to-be-woken/12793/4 "2021-06-07T23:12:18Z")

</div>

Thank you both,

@rtel I have, but being relatively new to freeRTOS things get confusing. Apologies if I sometimes ask silly questions or questions that I should already know the answer to or to which you have already explained but I most likely did not pick up as I should have

Thank you as always! 🙂
