- Hands-On Full Stack Development with Go
- Mina Andrawos
- 170字
- 2021-07-02 12:33:34
Go channels
An important question can now be addressed; what if we need to share a piece of data between two different goroutines?
In programs that make use of multiple threads, the common approach to share data between different threads is to lock the variables that are shared between the threads. This is typically known as the sharing memory approach. The following diagram demonstrates how two threads will share memory, by sharing a variable called X:

In Go, there is a very popular motto:
What does that mean? It simply means that Go does not typically prefer sharing memory (there are exceptions, however) between threads through the lock approach. Instead, Go prefers to communicate the data from one goroutine to another. This communicate part is achieved through the Go channels. The following diagram demonstrates how this looks visually:

Let's take a look at regular and buffered channels in the next sections.
- 微服務與事件驅動架構
- Django:Web Development with Python
- 假如C語言是我發明的:講給孩子聽的大師編程課
- Python編程實戰
- 從零開始學C#
- 小程序,巧應用:微信小程序開發實戰(第2版)
- OpenCV with Python Blueprints
- Python期貨量化交易實戰
- Visual Basic程序設計全程指南
- Julia High Performance(Second Edition)
- Mastering Embedded Linux Programming
- Building Clouds with Windows Azure Pack
- Unity與C++網絡游戲開發實戰:基于VR、AI與分布式架構
- Isomorphic JavaScript Web Development
- Learning Unity Physics