# fatal error: concurrent map read and map write

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

## Root Cause

One goroutine reads from a map while another writes to it without synchronization, causing a data race.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.18 | active | — | — |
| 1.19 | active | — | — |
| 1.20 | active | — | — |
| 1.21 | active | — | — |

## Workarounds

1. **Use sync.RWMutex to protect both reads and writes** (95% success)
   ```
   var mu sync.RWMutex
mu.RLock()
val := myMap[key]
mu.RUnlock()
   ```
2. **Use sync.Map for concurrent read/write** (90% success)
   ```
   var m sync.Map
m.Load(key) // safe concurrent read
   ```

## Dead Ends

- **Use a read-write lock (sync.RWMutex) only for writes** — If reads are not protected, they can still race with writes. (60% fail)
- **Use a copy of the map for reads** — Copying a map while it is being written is unsafe and can cause a race. (90% fail)
