{
  "id": "go/goroutine-race-condition",
  "signature": "WARNING: DATA RACE",
  "signature_zh": "警告：数据竞争",
  "regex": "WARNING:\\ DATA\\ RACE",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Multiple goroutines access the same variable concurrently without synchronization, and at least one is a write",
  "root_cause_type": "generic",
  "root_cause_zh": "多个协程并发访问同一变量且未同步，至少有一个是写操作",
  "versions": [
    {
      "version": "1.18",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding time.Sleep to reduce race likelihood",
      "why_fails": "Sleep does not synchronize access; race condition still exists and may manifest under different loads",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using atomic operations on non-atomic types",
      "why_fails": "Atomic package only works on specific types; using it incorrectly can cause data races",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use mutex to protect shared variable access",
      "success_rate": 0.9,
      "how": "var mu sync.Mutex\nvar counter int\nmu.Lock()\ncounter++\nmu.Unlock()",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use channels to communicate instead of sharing memory",
      "success_rate": 0.85,
      "how": "ch := make(chan int)\ngo func() {\n    ch <- 1\n}()\nval := <-ch",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-07-20",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}