Last active
September 12, 2018 16:51
-
-
Save rogerwelin/49eb95f88e1c3bbebc1a688113ed44dc to your computer and use it in GitHub Desktop.
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" | |
| ) | |
| // 4 | |
| func printer(msg string, wg *sync.WaitGroup) { | |
| defer wg.Done() | |
| fmt.Printf("Hello %s\n", msg) | |
| } | |
| func main() { | |
| // 1 | |
| greeks := []string{"plato", "socrates", "aristotle", "archimedes", "pythagoras", "democritus"} | |
| // 2 | |
| var wg sync.WaitGroup | |
| fmt.Println("Init") | |
| for _, philosopher := range greeks { | |
| // 3 | |
| wg.Add(1) | |
| go printer(philosopher, &wg) | |
| } | |
| // 5 | |
| wg.Wait() | |
| fmt.Println("End") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment