This is a creation in Article, where the information may have evolved or changed.
Goroutine:
Lightweight threads managed by Go run environment
Channel
There is a type of pipe, the operator is the direction of the <-data flow arrow pointing
Use make (Chan buffer data type buffer length) to create
Close the pipe using Close (chan), only the sender is allowed to close the pipe
Cases
CH: = Make (chan int 10)
CH <-10
A: = <-ch
Or
A: = Int (0)
A = <-Ch
One-way pipelines: one-way pipelines can only be used to send or receive data.
CH1: = make (chan int)
CH2: = <-chan int (CH1)//CH2 is defined as a read-only channel
CH3: = chan<-int (CH1)//CH3 is defined as a channel that can only be received
Select
In order for a goroutine to be able to wait on multiple communication operations, you can use Select
Select blocks until the communication in a branch is ready to continue.
When more than one communication is ready, a random one is selected for communication.
Synchronous:
The sync must be used to lock, the sync package provides two kinds of locks: sync. Mutex and sync. Rwmutex.
A mutex is the simplest mutex.
Rwmutex is also a mutex, but when read, it blocks the write, but does not prevent it from being read.