Skip to content

Instantly share code, notes, and snippets.

@irbekrm
Created October 22, 2020 06:37
Show Gist options
  • Save irbekrm/800499c2de4ad68bec655c66c11e588a to your computer and use it in GitHub Desktop.
Save irbekrm/800499c2de4ad68bec655c66c11e588a to your computer and use it in GitHub Desktop.
func main() {
// Initialize
var wg sync.WaitGroup
for i := 0; i < 5; i++ {
// Add 1 to the counter
wg.Add(1)
go hello(i, &wg)
}
// Wait blocks till the value of counter becomes 0
wg.Wait()
}
func hello(id int, wg *sync.WaitGroup) {
// Done decrements counter by one
defer wg.Done()
fmt.Printf("Hello from No %d!\n", id)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment