{
  "id": "go/goroutine-race-condition-write",
  "signature": "WARNING: DATA RACE (goroutine write)",
  "signature_zh": "警告：数据竞争（协程写操作）",
  "regex": "WARNING:\\ DATA\\ RACE\\ \\(goroutine\\ write\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Multiple goroutines access the same variable concurrently, with at least one write, without synchronization.",
  "root_cause_type": "generic",
  "root_cause_zh": "多个协程并发访问同一变量，且至少有一个写操作，没有同步机制。",
  "versions": [
    {
      "version": "1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Ignoring the race warning",
      "why_fails": "Data races lead to undefined behavior, crashes, or corrupted data.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using time.Sleep to synchronize",
      "why_fails": "Sleep does not guarantee ordering or atomicity; races persist.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use sync.Mutex to protect shared variable",
      "success_rate": 0.98,
      "how": "var mu sync.Mutex\nvar counter int\nfor i := 0; i < 10; i++ {\n    go func() {\n        mu.Lock()\n        counter++\n        mu.Unlock()\n    }()\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use atomic operations for simple types",
      "success_rate": 0.95,
      "how": "var counter int64\nfor i := 0; i < 10; i++ {\n    go func() {\n        atomic.AddInt64(&counter, 1)\n    }()\n}",
      "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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}