【发布时间】:2014-08-17 00:55:42
【问题描述】:
我正在学习 Go,我想尝试 goroutine 和通道。
这是我的代码:
package main
import "fmt"
func main(){
messages := make(chan string,3)
messages <- "one"
messages <- "two"
messages <- "three"
go func(m *chan string) {
fmt.Println("Entering the goroutine...")
for {
fmt.Println(<- *m)
}
}(&messages)
fmt.Println("Done!")
}
结果如下:
Done!
我不明白为什么我的 goroutine 从未被执行。 “进入 goroutine”没有打印出来,我也没有任何错误信息。
【问题讨论】:
标签: go