0xDEADLOCK embedded runtime_error ai_generated partial

FreeRTOS: Task 'SensorTask' blocked indefinitely on mutex 0x20000400 (owner: 'IdleTask')

ID: embedded/rtos-hang-on-mutex-lock

Also available as: JSON · Markdown · 中文
75%Fix Rate
85%Confidence
1Evidence
2024-03-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
FreeRTOS v10.4.6 active
FreeRTOS v11.0.0 active
CMSIS-RTOS2 v2.1.3 active

Root Cause

A mutex is held by a lower-priority task that is preempted or sleeping, causing priority inversion without a proper inheritance mechanism.

generic

中文

互斥锁被一个被抢占或休眠的低优先级任务持有,导致在没有正确优先级继承机制的情况下发生优先级反转。

Official Documentation

https://www.freertos.org/RTOS-software-timer-software-timer-service.html

Workarounds

  1. 80% success Enable priority inheritance by setting configUSE_MUTEXES and configUSE_PRIORITY_INHERITANCE to 1 in FreeRTOSConfig.h, then use xSemaphoreCreateMutex() instead of binary semaphores.
    Enable priority inheritance by setting configUSE_MUTEXES and configUSE_PRIORITY_INHERITANCE to 1 in FreeRTOSConfig.h, then use xSemaphoreCreateMutex() instead of binary semaphores.
  2. 70% success Add a timeout to mutex acquisition using xSemaphoreTake(mutex, pdMS_TO_TICKS(100)) and handle failure by releasing and retrying the mutex.
    Add a timeout to mutex acquisition using xSemaphoreTake(mutex, pdMS_TO_TICKS(100)) and handle failure by releasing and retrying the mutex.

中文步骤

  1. Enable priority inheritance by setting configUSE_MUTEXES and configUSE_PRIORITY_INHERITANCE to 1 in FreeRTOSConfig.h, then use xSemaphoreCreateMutex() instead of binary semaphores.
  2. Add a timeout to mutex acquisition using xSemaphoreTake(mutex, pdMS_TO_TICKS(100)) and handle failure by releasing and retrying the mutex.

Dead Ends

Common approaches that don't work:

  1. Increase the stack size of 'SensorTask' to prevent stack overflow 95% fail

    The issue is not stack size but mutex ownership; increasing stack does not resolve the priority inversion.

  2. Disable all interrupts to force task execution 90% fail

    Disabling interrupts can cause missed real-time deadlines and does not fix the mutex logic; it may worsen system responsiveness.