Skip to content

Instantly share code, notes, and snippets.

@fandyaditya
Last active July 10, 2026 06:17
Show Gist options
  • Select an option

  • Save fandyaditya/3353fc48383f42d2b7cce62bb840bdf0 to your computer and use it in GitHub Desktop.

Select an option

Save fandyaditya/3353fc48383f42d2b7cce62bb840bdf0 to your computer and use it in GitHub Desktop.
go snippet 1
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