- 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.
- 新編Visual Basic程序設(shè)計上機(jī)實驗教程
- Python概率統(tǒng)計
- Python科學(xué)計算(第2版)
- 技術(shù)領(lǐng)導(dǎo)力:程序員如何才能帶團(tuán)隊
- HTML5游戲開發(fā)案例教程
- 基于Swift語言的iOS App 商業(yè)實戰(zhàn)教程
- QGIS:Becoming a GIS Power User
- Java 9模塊化開發(fā):核心原則與實踐
- Getting Started with Laravel 4
- Salesforce Reporting and Dashboards
- Android應(yīng)用案例開發(fā)大全(第二版)
- Mastering Web Application Development with AngularJS
- Raspberry Pi Robotic Projects(Third Edition)
- Visual Basic語言程序設(shè)計基礎(chǔ)(第3版)
- MATLAB 2020 GUI程序設(shè)計從入門到精通