{
  "id": "go/concurrent-map-read-write",
  "signature": "fatal error: concurrent map read and map write",
  "signature_zh": "fatal error: 并发读写 map",
  "regex": "fatal\\ error:\\ concurrent\\ map\\ read\\ and\\ map\\ write",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "One goroutine read a map while another wrote to it. Go's runtime map has no internal locking and aborts on detected read/write races.",
  "root_cause_type": "generic",
  "root_cause_zh": "一个 goroutine 读 map 的同时另一个 goroutine 写该 map。Go 运行时 map 无内置锁，检测到读写竞态即终止。",
  "versions": [
    {
      "version": "1.0+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Struct fields are not atomic; concurrent access still races and may not even be detected, causing silent corruption.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The race detector adds large overhead and must be built in; it does not prevent the fatal error in non-race builds.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.97,
      "how": "var mu sync.RWMutex\nfunc get(k string) (V, bool) {\n    mu.RLock(); defer mu.RUnlock()\n    v, ok := m[k]; return v, ok\n}\nfunc set(k string, v V) {\n    mu.Lock(); defer mu.Unlock()\n    m[k] = v\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "type shard struct { mu sync.RWMutex; m map[string]V }\nshards := make([]shard, 32)\nidx := fnv32(k) % 32\nshards[idx].mu.Lock()\nshards[idx].m[k] = v\nshards[idx].mu.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.92,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-06-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}