# fatal error: concurrent map read and map write

- **ID:** `go/concurrent-map-read-write`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.0+ | active | — | — |

## Workarounds

1. **** (97% success)
   ```
   var mu sync.RWMutex
func get(k string) (V, bool) {
    mu.RLock(); defer mu.RUnlock()
    v, ok := m[k]; return v, ok
}
func set(k string, v V) {
    mu.Lock(); defer mu.Unlock()
    m[k] = v
}
   ```
2. **** (92% success)
   ```
   type shard struct { mu sync.RWMutex; m map[string]V }
shards := make([]shard, 32)
idx := fnv32(k) % 32
shards[idx].mu.Lock()
shards[idx].m[k] = v
shards[idx].mu.Unlock()
   ```

## Dead Ends

- **** — Struct fields are not atomic; concurrent access still races and may not even be detected, causing silent corruption. (80% fail)
- **** — The race detector adds large overhead and must be built in; it does not prevent the fatal error in non-race builds. (70% fail)
