我对下面的代码感到困惑,与,会改变程序行为有什么区别吗?go run go run -race-race
// test.go
package main
import "fmt"
func main() {
c := make(chan string)
go func() {
for i := 0; i < 2; i++ {
c <- "hello there"
}
}()
for msg := range c {
fmt.Println(msg)
}
}
当 时,结果为:go run test.go
hello there
hello there
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan receive]:
main.main()
/Users/donghui6/go/src/jd.com/iaas-sre/test/test.go:14 +0xf4
exit status 2
当 时,程序将挂起,如下所示:go run -race test.go
hello there
hello there
所以,谁能告诉我使用标志时发生了什么-race
倚天杖
素胚勾勒不出你
随时随地看视频慕课网APP
相关分类