package main import ( "fmt" "runtime" "sync" ) func main() { runtime.GOMAXPROCS(5) var m int32 = 0 var group sync.WaitGroup for i := 0; i < 100000; i++ { group.Add(1) go func() { defer func() { group.Done() }() // atomic.AddInt32(&m, 1) m++ // fmt.Println(m) }() } group.Wait() fmt.Print(m) }