# WARNING: DATA RACE

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

## Root Cause

Multiple goroutines access the same variable concurrently without synchronization, and at least one is a write

## Version Compatibility

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

## Workarounds

1. **Use mutex to protect shared variable access** (90% success)
   ```
   var mu sync.Mutex
var counter int
mu.Lock()
counter++
mu.Unlock()
   ```
2. **Use channels to communicate instead of sharing memory** (85% success)
   ```
   ch := make(chan int)
go func() {
    ch <- 1
}()
val := <-ch
   ```

## Dead Ends

- **Adding time.Sleep to reduce race likelihood** — Sleep does not synchronize access; race condition still exists and may manifest under different loads (95% fail)
- **Using atomic operations on non-atomic types** — Atomic package only works on specific types; using it incorrectly can cause data races (80% fail)
