# FreeRTOS：在句柄 0x2000ABCD 上检测到互斥锁死锁，任务 'SensorTask' 无限期阻塞

- **ID:** `embedded/freertos-mutex-deadlock-detected`
- **领域:** embedded
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

两个任务持有并等待互斥锁形成循环依赖，或任务尝试获取已持有的互斥锁但未使用递归互斥锁类型。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| FreeRTOS 10.5.1 | active | — | — |
| CMISIS-RTOS2 2.1.3 | active | — | — |
| ARM GCC 11.3.1 | active | — | — |

## 解决方案

1. ```
   Use recursive mutex (xSemaphoreCreateRecursiveMutex) instead of standard mutex if same task needs to take mutex multiple times. Replace all xSemaphoreTake() with xSemaphoreTakeRecursive().
   ```
2. ```
   Implement mutex lock ordering: ensure all tasks acquire mutexes in the same global order (e.g., always lock sensor mutex before display mutex). Add assert checks using configUSE_MUTEX_DEADLOCK_DETECTION.
   ```

## 无效尝试

- **Increase task stack size to avoid blocking** — Deadlock is caused by mutex logic, not stack overflow; larger stack does not resolve circular wait. (95% 失败率)
- **Reduce mutex timeout value to force task to give up** — Reducing timeout may cause task to abandon operation prematurely, leading to data corruption or incomplete processing. (80% 失败率)
