Summary of go language series basic tutorials (4)

1. Goroutines and channels    

A goroutine is created every time it is executed go func(), including the function and context information to be executed.

Goroutine is the concurrent execution of Go programs channeland the communication channel between them.

var ch1 chan int. //declare an integer channel

2. Channel common operations

//Define a channel
channel :=make(chan int)

//Send value to channel
channel <- 10 

 //Receive the value and assign it to the variable x
x:= <- channel 

//Closeclose
(channel) 

3. selectKeyword, responding to multiple channel operations at the same time

select { case v1<-channel1:     //... case v2 := <-channel2:     //... case channel3 <- 10:     //... default:     //default operation }








Guess you like

Origin blog.csdn.net/u013558123/article/details/131452045