why can not run go function in go? -
this question has answer here:
this below code:
func main() { values := []int{1, 2, 3, 4} _, v := range values { go func(x int) { fmt.println(x) }(v) } }
if code have not go
keyword, print 1, 2, 3, 4
.
but can not print code now, why?
go version: 1.5.2 darwin/amd64
short: place wait @ end , print.
better option: communicate termination via channels.
long: go program lives long main goroutine lives.
when go somefunc()
, it's not started immediately, somefunc() gets scheduled.
in case schedule goroutines , quit – , there's no reason scheduler run other goroutines.
Comments
Post a Comment