# WARNING: DATA RACE: Write by goroutine X, Read by goroutine Y (closure variable)

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

## Root Cause

Goroutine closures capture loop variables by reference, causing multiple goroutines to race on the same variable.

## Version Compatibility

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

## Workarounds

1. **Pass loop variable as argument to goroutine** (99% success)
   ```
   for i := 0; i < 10; i++ {
    go func(val int) {
        fmt.Println(val)
    }(i)
}
   ```
2. **Create local copy within loop** (98% success)
   ```
   for i := 0; i < 10; i++ {
    val := i
    go func() {
        fmt.Println(val)
    }()
}
   ```

## Dead Ends

- **Adding time.Sleep in loop to stagger goroutines** — Race condition still exists; timing-dependent fix unreliable. (90% fail)
- **Using global variable instead of local** — Global variable is shared; race condition worsens. (80% fail)
