Last active
July 10, 2026 06:17
-
-
Save fandyaditya/3353fc48383f42d2b7cce62bb840bdf0 to your computer and use it in GitHub Desktop.
go snippet 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "sync" | |
| ) | |
| func increment(counter *int, wg *sync.WaitGroup) { | |
| defer wg.Done() | |
| *counter++ | |
| } | |
| func main() { | |
| counter := 0 | |
| var wg sync.WaitGroup | |
| for i := 0; i < 1000; i++ { | |
| wg.Add(1) | |
| go increment(&counter, &wg) | |
| } | |
| wg.Wait() | |
| fmt.Println("counter:", counter) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment