# WARNING: DATA RACE (goroutine write)

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

## Root Cause

Multiple goroutines access the same variable concurrently, with at least one write, without synchronization.

## Version Compatibility

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

## Workarounds

1. **Use sync.Mutex to protect shared variable** (98% success)
   ```
   var mu sync.Mutex
var counter int
for i := 0; i < 10; i++ {
    go func() {
        mu.Lock()
        counter++
        mu.Unlock()
    }()
}
   ```
2. **Use atomic operations for simple types** (95% success)
   ```
   var counter int64
for i := 0; i < 10; i++ {
    go func() {
        atomic.AddInt64(&counter, 1)
    }()
}
   ```

## Dead Ends

- **Ignoring the race warning** — Data races lead to undefined behavior, crashes, or corrupted data. (95% fail)
- **Using time.Sleep to synchronize** — Sleep does not guarantee ordering or atomicity; races persist. (90% fail)
