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

- **ID:** `embedded/rtos-hang-on-mutex-lock`
- **Domain:** embedded
- **Category:** runtime_error
- **Error Code:** `0xDEADLOCK`
- **Verification:** ai_generated
- **Fix Rate:** 75%

## Root Cause

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

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| FreeRTOS v10.4.6 | active | — | — |
| FreeRTOS v11.0.0 | active | — | — |
| CMSIS-RTOS2 v2.1.3 | active | — | — |

## Workarounds

1. **Enable priority inheritance by setting configUSE_MUTEXES and configUSE_PRIORITY_INHERITANCE to 1 in FreeRTOSConfig.h, then use xSemaphoreCreateMutex() instead of binary semaphores.** (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.
   ```
2. **Add a timeout to mutex acquisition using xSemaphoreTake(mutex, pdMS_TO_TICKS(100)) and handle failure by releasing and retrying the mutex.** (70% success)
   ```
   Add a timeout to mutex acquisition using xSemaphoreTake(mutex, pdMS_TO_TICKS(100)) and handle failure by releasing and retrying the mutex.
   ```

## Dead Ends

- **Increase the stack size of 'SensorTask' to prevent stack overflow** — The issue is not stack size but mutex ownership; increasing stack does not resolve the priority inversion. (95% fail)
- **Disable all interrupts to force task execution** — Disabling interrupts can cause missed real-time deadlines and does not fix the mutex logic; it may worsen system responsiveness. (90% fail)
