0xDEADLOCK embedded runtime_error ai_generated partial

FreeRTOS: 任务'SensorTask'在互斥锁0x20000400上无限阻塞(所有者:'IdleTask')

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

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

其他格式: JSON · Markdown 中文 · English
75%修复率
85%置信度
1证据数
2024-03-15首次发现

版本兼容性

版本状态引入弃用备注
FreeRTOS v10.4.6 active
FreeRTOS v11.0.0 active
CMSIS-RTOS2 v2.1.3 active

根因分析

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

English

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

generic

官方文档

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

解决方案

  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.

无效尝试

常见但无效的做法:

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

    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% 失败

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