Sharing Memory Using Goroutines
Let’s learn how to share memory using goroutines.
We'll cover the following...
We'll cover the following...
The monitor goroutine
This lesson illustrates how to share data using a dedicated goroutine. Although shared memory is the traditional way that threads communicate with each other, Go comes with built-in synchronization features that allow a single goroutine to own a shared piece of data. This means that other goroutines must send messages to this single goroutine that owns the shared data, which prevents the corruption of the data. Such a goroutine is called a monitor goroutine. In Go terminology, this is sharing by communicating instead of communicating by sharing.
Note: We can use a monitor goroutine ...