知识卡片
无缓冲通道形成会合点
通道按元素类型传值;无缓冲通道的发送等待接收方,接收也等待发送方,因此一次成功通信构成协作会合点。书中的ping/pong先后输出由通信约束产生,而非偶然调度。没有匹配方就会等待,设计时必须确认谁负责推进。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Go Language Foundations · 查看原书依据
Unbuffered channels have a very useful property in that sends on them block until another goroutine receives on the channel, and receives block until another goroutine sends on the channel. This behavior can be exploited to synchronize two goroutines, as demonstrated below: func main() { ch := make(chan string) // Allocate a string channel go
参考来源
- 位置:《Cloud Native Go》第03章《Go Language Foundations》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch03.xhtml)
- 结论依据:通道按元素类型传值;无缓冲通道的发送等待接收方,接收也等待发送方,因此一次成功通信构成协作会合点。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。
- 原始内容:Unbuffered channels have a very useful property in that sends on them block until another goroutine receives on the channel, and receives block until another goroutine sends on the channel. This behavior can be exploited to synchronize two goroutines, as demonstrated below: func main() { ch := make(chan string) // Allocate a string channel go