- 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.
- R語言經典實例(原書第2版)
- 學Python也可以這么有趣
- 網站構建技術
- OpenStack Orchestration
- Kubernetes進階實戰
- JavaScript動態網頁編程
- .NET 4.5 Parallel Extensions Cookbook
- 代替VBA!用Python輕松實現Excel編程
- 軟件工程基礎與實訓教程
- Mastering Docker
- Python Machine Learning Blueprints:Intuitive data projects you can relate to
- Android Sensor Programming By Example
- 會當凌絕頂:Java開發修行實錄
- 零基礎PHP從入門到精通
- 少年小魚的魔法之旅:神奇的Python