func Chan3() {
<-c
c <- 0
fmt.Println("done")
}
var c = make(chan int)
var a string
func f() {
a = "hello, world" //1
<-c //2
}
func Chan2() {
go f() //3
c <- 0 //4
fmt.Print("打印:", a) //5
}
Created
June 9, 2019 18:19
-
-
Save yanjinbin/892fee22d119284dbea6c3614c0976c4 to your computer and use it in GitHub Desktop.
为什么Chan2方法可以跑通,Chan3一直无限循环呢
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/questions/18660533/why-using-unbuffered-channel-in-the-same-goroutine-gives-a-deadlock
这篇文章讲的不错 关于unbuffer channel 的 同步