This is a creation in Article, where the information may have evolved or changed.
Package Mainimport ("FMT" "Runtime") func main () {runtime. Gomaxprocs (runtime. NUMCPU ()) c: = Make (chan bool, ten) for I: = 0; I < 10; i++ {Go Go (c, i)}for I: = 0; I < 10; i++ {<-c}}func Go (c chan bool, index int) {A: = 1for I: = 0; i <; i++ {a + = i}fmt. PRINTLN (Index, a) C <-true}
Package Mainimport ("FMT" "Runtime" "Sync") func main () {runtime. Gomaxprocs (runtime. NUMCPU ()) WG: = Sync. WAITGROUP{}WG. ADD (+) for I: = 0; I < 10; i++ {Go Go (&WG, i)}wg. Wait ()}func Go (WG *sync. Waitgroup, index int) {A: = 1for I: = 0; i <; i++ {a + = i}fmt. PRINTLN (Index, a) WG. Done ()}
Package Mainimport ("FMT") func main () {c: = make (chan int) go func () {for V: = range C {fmt. Println (v)}} () for {select {case c <-0:case C <-1:}}}
Reference: [1]. Https://github.com/Unknwon/go-fundamental-programming/blob/master/lectures/lecture14.md