- 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.
- HTML5+CSS3王者歸來
- Java程序設計與開發
- Programming ArcGIS 10.1 with Python Cookbook
- Dependency Injection in .NET Core 2.0
- Visual C
- JSP開發案例教程
- Yocto for Raspberry Pi
- 從Excel到Python:用Python輕松處理Excel數據(第2版)
- Python Data Structures and Algorithms
- The Professional ScrumMaster’s Handbook
- ASP.NET程序開發范例寶典
- Java多線程并發體系實戰(微課視頻版)
- Yii2 By Example
- Ubuntu Server Cookbook
- 從零開始學UI設計·基礎篇