Puzzle 22 Explanation: Go Count
Understand how different packages work in Go.
We'll cover the following...
Try it yourself
Try executing the code below to see the result.
Press + to interact
package mainimport ("fmt""sync")func main() {var count intvar wg sync.WaitGroupfor i := 0; i < 1_000_000; i++ {wg.Add(1)go func() {defer wg.Done()count++}()}wg.Wait()fmt.Println(count)}
Explanation
What we have here is a race condition. We ...
Access this course and 1400+ top-rated courses and projects.