For the last day and a bit, I’ve been debugging a problem with nested mutexes and priority inheritance on FreeRTOS 9.0.0. The flow was as follows (mutexes are FS and SPI, Task3 has priority 3, Task1 has 1):
Task1: Take(FS), Take(SPI);
Task3: Take(SPI) – taken, Task1 inherits priority 3
Task1: Give(SPI) – but xTaskPriorityDisinherit seems to fail, as it also holds the FS mutex
Task1: Take(SPI) … until Give(SPI), Give(FS).
Task3: takes spi and does it’s job.
However, the FS operation is quite long and should have been interrupted by Task3. After I looked at the code I realized, that the priority inheritance algorithm is extremely simplified and doesn’t handle our case, due to multiple mutexes taken at the same time.
This is fine, however, it would be nice if the documentation would alert us to the limitations, as even after knowing what the problem is, I only found out some information in the forums. There seems to be some reference to the docs, but I didn’t find it.
Furthermore, do you have any suggestion on how to solve the problem above? Obviously I need to make sure that the priority gets disinherited, and I probably could write some code myself to do that in the task (as it gives back the mutex, decrease the priority). Other solution is to use mutexes only when the priority inheritance is necessary and binary semaphores everywhere else. However, I’ve got the feeling that both solutions will come and bite me back later.