Created
October 22, 2020 06:37
-
-
Save irbekrm/800499c2de4ad68bec655c66c11e588a to your computer and use it in GitHub Desktop.
This file contains 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
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