# fatal error: concurrent slice writes

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

## Root Cause

Multiple goroutines append to the same slice without synchronization, causing a data race.

## Version Compatibility

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

## Workarounds

1. **Use a mutex to protect slice appends.** (95% success)
   ```
   var mu sync.Mutex
var slice []int

func appendValue(v int) {
    mu.Lock()
    slice = append(slice, v)
    mu.Unlock()
}
   ```
2. **Use a channel to aggregate results from goroutines.** (90% success)
   ```
   ch := make(chan int, 100)
for i := 0; i < n; i++ {
    go func() {
        ch <- compute()
    }()
}
var results []int
for i := 0; i < n; i++ {
    results = append(results, <-ch)
}
   ```

## Dead Ends

- **Using a channel to serialize appends but not draining the channel properly.** — If channel is buffered and not drained, goroutines may block or deadlock. (70% fail)
- **Assuming append is atomic.** — append is not atomic; it may read and update the slice header concurrently, causing corruption. (90% fail)
