OneBug This week's bugs
Spot the bug Go
1
package main
2
 
3
import (
4
	"fmt"
5
	"sync"
6
)
7
 
8
func main() {
9
	counts := map[int]int{}
10
	var wg sync.WaitGroup
11
	for i := 0; i < 500; i++ {
12
		wg.Add(1)
13
		go func(n int) {
14
			defer wg.Done()
15
			counts[n%10]++
16
		}(i)
17
	}
18
	wg.Wait()
19
	fmt.Println(len(counts))  // fatal error: concurrent map writes
20
}

Read the full write-up for this bug (spoilers)