Puzzle 22 | Count Me a Million |
| package main |
| |
| import ( |
| "fmt" |
| "sync" |
| ) |
| |
| func main() { |
| var count int |
| var wg sync.WaitGroup |
| |
| for i := 0; i < 1_000_000; i++ { |
| wg.Add(1) |
| go func() { |
| defer wg.Done() |
| count++ |
| }() |
| |
| } |
| wg.Wait() |
| fmt.Println(count) |
| } |
Guess the Output | |
---|---|
Try to guess what the output is before moving to the next page. |
This code will print: 891239
Different Output | |
---|---|
Your output might ... |
Get Go Brain Teasers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.