{
  "id": "embedded/freertos-mutex-recursive-take",
  "signature": "FreeRTOS: xSemaphoreTakeRecursive failed on mutex 0x2000A000, mutex already taken by same task",
  "signature_zh": "FreeRTOS：xSemaphoreTakeRecursive在互斥锁0x2000A000上失败，互斥锁已被同一任务获取",
  "regex": "FreeRTOS.*xSemaphoreTakeRecursive failed.*mutex 0x[0-9A-Fa-f]+.*already taken by same task",
  "domain": "embedded",
  "category": "assertion_error",
  "subcategory": null,
  "root_cause": "A recursive mutex was taken by a task that already holds it without a corresponding recursive give, exhausting the nesting count.",
  "root_cause_type": "generic",
  "root_cause_zh": "一个递归互斥锁被已持有它的任务获取，而没有相应的递归释放，耗尽了嵌套计数。",
  "versions": [
    {
      "version": "FreeRTOS v10.5.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "ARM GCC v12.2.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Replace recursive mutex with a standard mutex",
      "why_fails": "A standard mutex will cause a deadlock if the same task tries to take it again, as it does not support recursive acquisition.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Increase the configMAX_RECURSIVE_MUTEX_DEPTH value",
      "why_fails": "The depth is limited by task stack and memory; increasing it may mask the underlying nesting bug, leading to stack overflow later.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Add a delay before taking the mutex again",
      "why_fails": "Does not resolve the logic error; the mutex is already held, so delay only wastes CPU cycles without fixing the nesting count.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure every xSemaphoreTakeRecursive is paired with an equal number of xSemaphoreGiveRecursive calls. Use a debug macro to track nesting count.",
      "success_rate": 0.95,
      "how": "Ensure every xSemaphoreTakeRecursive is paired with an equal number of xSemaphoreGiveRecursive calls. Use a debug macro to track nesting count.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Refactor code to avoid recursive mutex acquisition by using a single entry point that acquires the mutex once and calls nested functions without re-acquiring.",
      "success_rate": 0.85,
      "how": "Refactor code to avoid recursive mutex acquisition by using a single entry point that acquires the mutex once and calls nested functions without re-acquiring.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Ensure every xSemaphoreTakeRecursive is paired with an equal number of xSemaphoreGiveRecursive calls. Use a debug macro to track nesting count.",
    "Refactor code to avoid recursive mutex acquisition by using a single entry point that acquires the mutex once and calls nested functions without re-acquiring."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.freertos.org/a00122.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.89,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2024-11-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}