Open kkdai opened 3 years ago
comment written by 張皓傑, created at 16 Jan 18 08:58 UTC,
你好,最近在學golang,有幸學習您的文章,關於你的deadlock例子,我認為是因為channel必須跟gorutine同時存在,所以邏輯判斷上應該是有確定要使用gorutine時,才建立channel,
func main() {
totalResult := 0
needRoutine := false
if needRoutine == true {
c := make(chan int)
go func() {
result := 1
c <- result
}()
totalResult = <-c*3 + 5
} else {
//do nothing
}
fmt.Printf("result is %d", totalResult)
}
不過跟你的解法其實差不多就是了 :)
comment written by Evan Lin, created at 16 Jan 18 16:15 UTC,
感謝你留言我好幾年前的文章,如果你對 channel 興趣強烈建議你看這段 talk https://www.youtube.com/wat...
comment written by 張皓傑, created at 17 Jan 18 03:04 UTC,
感謝~這系列的影片感覺很實用!
comment written by 資管系黃伯睿, created at 29 Dec 18 10:00 UTC,
大錯特錯
If the channel is unbuffered, the sender blocks until the receiver has received the value.
[Golang]關於Channels的控制一些要注意的事項(一)
http://www.evanlin.com/go-channels-handle/