I’m using the FreeRTOS v5.0.0 with a PIC18 mcu and the MPLAB building toolchain. I have two tasks, with the same priority (tskIDLE_PRIORITY + 1). Task T1 sends a message every two seconds (using vTaskDelayUntil) to a Queue and Task T2 receives this message from the Queue using a blocking xQueueReceive (meaning porTMAX_DELAY is used as blocking time and vTaskSuspend support is enabled) and sends it over the serial. System hangs for some reason Monitoring what happens the execution sequence until system stops is: 1) T2 starts execution and blocks waiting for a message to arrive at the Queue 2) T1 starts execution, successfully waits for two seconds and then calls XQueueSend System is hanged! I’ve pinpointed the problem on using taskYIELD() inside the critical section of xQueueGenericSend(). When T2 is removed from the event list, xTaskRemoveFromEventList() returns pdTRUE because both tasks have the same priority (it’s supposed to return true if the unblocked task has higher priority but it works the same way for equal priorities too). The taskYIELD() following for some reasons fails. Any ideas? I’m still looking out why this is happening. If I comment out taskYIELD() everything works fine. ggeorgak
Just to answer the part on trying to switch to the receiving task when it has the same priority as the sending task: I wouldn’t want to second-guess Richard’s intent here, but this is probably just an optimization (which is also done in the Erlang language runtime when one Erlang process sends a message to another one if I remember correctly). If two tasks do have the same priority, the scheduler is free to choose which one to execute. If one of them is trying to get a message from a queue, it is often more efficient to schedule it so that one place in the queue can be freed. This optimization reduces the chance of later having a higher priority task block because it wants to write into the queue, thus causing a priority inversion. It’s generally best to have empty queues than full ones.
Could it simply be a stack overflow? Regards.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.