有谁可以帮我写个多线程的例子吗?

bianweiall · · 4744 次点击
谢谢你了!就需要这个!
#2
更多评论
polaris
社区,需要你我一同完善!
简单的例子: package main import ( "fmt" "time" "strconv" "runtime" ) func main() { runtime.GOMAXPROCS(runtime.NumCPU()) strCh := make(chan string, 10) go AddStr(strCh, "polaris") go AddStr(strCh, "studygolang") go PrintStr(strCh, 1) go PrintStr(strCh, 2) time.Sleep(3e9) } func AddStr(ch chan <- string, str string) { for i := 0; i < 100; i++ { ch <- str + strconv.Itoa(i) } } func PrintStr(ch <- chan string, i int) { for { select { case str := <- ch: fmt.Println("i=", i, str) break } } }
#1