Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


Nested mutexes and priority inheritance (again)

Posted by ladislavlaska on June 12, 2017


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.


Nested mutexes and priority inheritance (again)

Posted by rtel on June 15, 2017

Sorry for the delay in replying:

You are right that the priority inheritance mechanism is simplified. It was considered the best compromise between code size and functionality. A full priority inheritance mechanism is very complex and involves stacking priorities, two way associations, priority ordered lists of tasks waiting on mutexes, etc. As it is, if a task takes two mutexes, it will not di-inherit any inherited priority until both mutexes have been given back.

I've just looked in the book, and you are right, this does need documenting better (at all).

Version 9.0.1, which is currently only available from the SVN repository directly, had some work done on improving prioritiy inheritance, but I can't recall exactly what (without looking through the check-in comments).

It may be the code can be re-factored to avoid the situation you describe, but that would require a lot more information on your system and some time to determine (which is outside the scope of our support here).

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists