Skip to content

Instantly share code, notes, and snippets.

@rogerwelin
Last active September 12, 2018 16:51
Show Gist options
  • Select an option

  • Save rogerwelin/49eb95f88e1c3bbebc1a688113ed44dc to your computer and use it in GitHub Desktop.

Select an option

Save rogerwelin/49eb95f88e1c3bbebc1a688113ed44dc to your computer and use it in GitHub Desktop.
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