我有一小段这样的代码
func main() {
var c chan string
go func() {
c <- "let's get started"//write1
//c <- "let's get started"//write2
//c <- "let's get started"//write3
fmt.Println("wrote the stuff....")
}()
//time.Sleep(3 * time.Second) //adding this always shows fatal exception
c = make(chan string)
fmt.Println(<-c)
}
如果我取消注释wrote the stuff....
和//write2
代码片段行,我在控制台上看不到输出write3
。我知道可能我不认为这是因为通道是无缓冲且完全同步的,并且通道外只有一次读取。然而,当程序退出时,go例程被阻止,为什么没有像deadlocked...
这样的错误或者我看到的这种情况?