go routine 是轻量级的线程
参考:https://studygolang.com/articles/4071
go fun_name()
go func() {fmt.Println("test")}()
chan 在 routine间传递数据
http://www.jb51.cc/article/p-kshlvjoj-bqq.html
ch:=make(chan int,1)
ch<-1
fmt.Println(<-ch)
注意,buffered channel 和 unbuffered channel 的区别,unbuffer channel 发达时也会阻塞
https://studygolang.com/articles/8021
//下面这样会报死锁
ch:=make(chan int) //make 没有指定长度
ch<-1
fmt.Println(<-ch)
select
https://blog.csdn.net/john_f_lau/article/details/55254324
注意select有default 则会不断轮询,如果没有default会阻塞?
func tick_test(){
tick := time.Tick(10000 * time.Millisecond)
abort:=make(chan struct{})
go func() {
os.Stdin.Read(make([]byte,1))
abort<- struct {}{}
}()
select {
case t:=<-tick:
fmt.Println("tick.",t)
case <-abort:
fmt.Println("abort")
return
default:
fmt.Println("...")
}
}
context
https://www.cnblogs.com/zhangboyu/p/7456606.html
https://studygolang.com/articles/10155?fr=sidebar