{
  "id": "go/data-race-on-shared-counter",
  "signature": "WARNING: DATA RACE\nRead at 0x... by goroutine N:\n  main.main.func1()\nPrevious write at 0x... by goroutine M:",
  "signature_zh": "WARNING: DATA RACE\n由 goroutine N 在 0x... 读取：\n  main.main.func1()\n由 goroutine M 在 0x... 先前写入：",
  "regex": "WARNING:\\ DATA\\ RACE\\\nRead\\ at\\ 0x\\.\\.\\.\\ by\\ goroutine\\ N:\\\n\\ \\ main\\.main\\.func1\\(\\)\\\nPrevious\\ write\\ at\\ 0x\\.\\.\\.\\ by\\ goroutine\\ M:",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Multiple goroutines read and write a shared variable without synchronization. The race detector reports the conflicting accesses.",
  "root_cause_type": "generic",
  "root_cause_zh": "多个 goroutine 在无同步的情况下读写共享变量，race detector 报告了冲突访问。",
  "versions": [
    {
      "version": "1.0+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Hides the symptom but the underlying race still corrupts data and can crash in production.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "unsafe does not provide synchronization; the race remains.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "var counter int64\natomic.AddInt64(&counter, 1)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.93,
      "how": "var mu sync.Mutex\nmu.Lock()\ncounter++\nmu.Unlock()",
      "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.89,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-08",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}