# fatal error: concurrent map writes

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

## Root Cause

Multiple goroutines write to a Go map without synchronization, causing a runtime crash.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.21 | active | — | — |
| 1.22 | active | — | — |

## Workarounds

1. **Use sync.Mutex to protect all map access** (98% success)
   ```
   var mu sync.Mutex
m := make(map[string]int)
// write
mu.Lock()
m["key"] = 1
mu.Unlock()
// read
mu.Lock()
val := m["key"]
mu.Unlock()
   ```
2. **Use sync.Map for concurrent-safe map operations** (90% success)
   ```
   var m sync.Map
m.Store("key", 1)
val, ok := m.Load("key")
   ```

## Dead Ends

- **Using a mutex only for writes but not reads** — Concurrent reads during writes can also cause race conditions. (80% fail)
- **Using a sync.Map incorrectly** — sync.Map has specific use cases; misuse can still cause races. (65% fail)
