A goroutine is a loghtweight thread of execution
package main import ( "fmt" ) func f(form string) { for i := 0; i < 3; i++ { fmt.Println(form, ";", i) } } func main() { f("direct") go f("goroutine") go func(msg string) { fmt.Println(msg) }("going") var input string fmt.Scanln(&input) fmt.Println("done") }
direct ; 0 direct ; 1 direct ; 2 goroutine ; 0 goroutine ; 1 goroutine ; 2 going xxjkx done
总结 :
1 : ....
有疑问加站长微信联系(非本文作者)