// Chapter 38 example: ten goroutines add to one counter with no protection, // and some of the additions are lost. The total is wrong, and it changes from // run to run. // Run with: go run exercises/38/01-lost-updates.go package main import ( "fmt" "sync" ) func main() { count := 0 var wg sync.WaitGroup for range 10 { wg.Go(func() { for range 100000 { count = count + 1 } }) } wg.Wait() fmt.Println("Expected: 1000000") fmt.Println("Got: ", count) }