Last active
October 22, 2020 06:42
-
-
Save irbekrm/854dafa821e5305dfa2092c3c9f46a7f 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