# FreeRTOS: mutex deadlock detected on handle 0x2000ABCD, task 'SensorTask' blocked indefinitely

- **ID:** `embedded/freertos-mutex-deadlock-detected`
- **Domain:** embedded
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

Circular dependency between two tasks holding and waiting for mutexes, or a task attempts to take a mutex it already holds without recursive mutex type.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| FreeRTOS 10.5.1 | active | — | — |
| CMISIS-RTOS2 2.1.3 | active | — | — |
| ARM GCC 11.3.1 | active | — | — |

## Workarounds

1. **Use recursive mutex (xSemaphoreCreateRecursiveMutex) instead of standard mutex if same task needs to take mutex multiple times. Replace all xSemaphoreTake() with xSemaphoreTakeRecursive().** (95% success)
   ```
   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.** (90% success)
   ```
   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.
   ```

## Dead Ends

- **Increase task stack size to avoid blocking** — Deadlock is caused by mutex logic, not stack overflow; larger stack does not resolve circular wait. (95% fail)
- **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% fail)
