Golang Channel

之前写过一篇文章 《关于对「Don’t communicate by sharing memory, share memory by communicating」的理解》 ,在里面介绍了我对Golang CSP设计理念中「通信」概念的理解。 所以,与前者不同的是,本篇更注重Channel相关底层实现的探索。 数据结构 type hchan struct { qcount uint // 当前队列中的元素数量 dataqsiz uint // chan...

二月 10, 2025 · 9 分钟 · 4477 字 · ZhangYong

关于对「Don't communicate by sharing memory, share memory by communicating」的理解

Golang编程谚语(Proverbs)中有这么一句: Don’t communicate by sharing memory, share memory by communicating. 即:不要使用共享内存通信,用通信来实现数据的共享。 首先 Go 的并发原语 (goroutines 和 channels) 为构造并发软件提供了一种优雅而独特的手段. Go 鼓励使用 channels 在 goroutines 之间传递对数据的拷贝, 而不是显式地使用锁来调解对共享数据的访问. 这种方法确保只...

五月 20, 2024 · 4 分钟 · 1803 字 · ZhangYong