Deadlock

5. 4.4 Debugging avec vTaskList et stack high-water mark

5.3. Deadlock

Tâche A tient mutex 1, attend mutex 2. Tâche B tient mutex 2, attend mutex 1. Les deux se bloquent mutuellement.

// Anti-pattern deadlock
xSemaphoreTake(xMutexA, portMAX_DELAY);  // OK
xSemaphoreTake(xMutexB, portMAX_DELAY);  // deadlock si tâche B fait l'inverse

// Fix : timeout fini + ordre canonique d'acquisition
if (xSemaphoreTake(xMutexA, pdMS_TO_TICKS(100)) != pdTRUE) {
    ESP_LOGE("TASK", "Mutex A timeout — potential deadlock");
    return;
}
if (xSemaphoreTake(xMutexB, pdMS_TO_TICKS(100)) != pdTRUE) {
    xSemaphoreGive(xMutexA);  // libérer ce qu'on tient déjà !
    ESP_LOGE("TASK", "Mutex B timeout — potential deadlock");
    return;
}

Se connecter pour suivre votre progression.