"The Way to Go" ---- page 395
>
The code which calls this method can then iterate over the container like:
```go
for x := range container.Iter() { ... }
```
which can run in its own goroutine, so then the above iterator employs a channel and two goroutines (which may run in separate threads). Then we have a typical producer-consumer pattern. If the program terminates before the goroutine is done writing values to the channel, then that goroutine will not be garbage collected; this is by design(这是指Golang的design还是上面那段代码的design?). This seems like wrong behavior, but channels are for threadsafe communication(不太明白这种行为和和线程安全有什么关系). In that context, a goroutine hung trying to write to a channel that nobody will ever read from is probably a bug and not something you’d like to be silently garbage-collected.(因为上面那个design到底指的谁我不太明白,所以这个地方到底是想表达“这看起来像bug(如果之前指的是golang的design)”,还是像表达“这样就是一个bug”(如果指之前的代码的design),不要这样写)
对这一段的疑问我都在上面的括号里写出来了,还望解惑,谢谢各位大佬!
有疑问加站长微信联系(非本文作者)