xQueueSend() switching to a higher priority task

Hi,
my understanding it that xQueueSend() switches to the task that has a xQueueReceive() for that message if said xQueueReceive() task has a higher priority and despite the xQueueSend() still not having completed its time slot/tick.

  1. if the higher priority task is not sitting/waiting in the xQueueSend() does it still switches to that higher priority task or not?

  2. is that behaviour only for queues or for other structures too? Where can I see a summary of all the situations/functions with such behaviour? I couldn’t find any in the API or the manual but probably just missed it or looking for the wrong thing.

Thank you

  1. if the higher priority task is not sitting/waiting in the xQueueSend() does it still switches to that higher priority task or not?

No. If a task is not blocked on a queue then it cannot be unblocked when a message becomes available from that queue (why would it be rather than any other task?). Also if there is a higher priority task that is not running then it must be blocked on something else, so sending a message to the queue would not unblock it anyway.

Applies to all communication and synchronisation primitives.

The normal behavior of FreeRTOS is that you are ALWAYS running the highest priority task that is ready. ‘Time Slots’ only have bearing if you have multiple tasks at the same priority level that are ready, and you have Time Slicing enabled, at which point then they are rotated through each tick.

Note, this does NOT mean that each will always get the same about of execution time, as higher priority tasks running isn’t taken into account in this calculation and tasks can lose their ‘place’ by blocking on something or explicitly yielding.

The only way you situation could come about is if you had turned off Pre-emption, at which point if an ISR made a higher task ready then because preemption is off, the switching is delayed to a ‘preemption point’, which I will admit I am not positive exactly what qualifies, but I wouldn’t be surprised if a call to xQueueSend() was one (it definitely would be if it unblocked a higher priority task). I am not that familiar with non-preemptive mode as I don’t use it, in my mind it is for system that aren’t that ‘real-time’ but just want some multi-tasking, and it simplifies a lot of race conditions.

Thank you both for the explanation! :slight_smile:

thanks my issue has been fixed.