package main
import ( "fmt" "net" )
var temp net.IP
func main() { fmt.Println("start......") ch := make(chan int) <-ch fmt.Println("hello world") }
/* start......
*/
package main
import ( "fmt" )
func main() { fmt.Println("start......") ch := make(chan int) <-ch fmt.Println("hello world") }
/* start...... fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan receive]: main.main() */
1
koujianshusheng OP 一个堵塞一个死锁,就因为 net 包?
|
2
youngzy 2022 年 5 月 27 日
第一个应该也是死锁,没有创建新的协程,主协程阻塞。
去 play ground 试试? |
3
koujianshusheng OP @youngzy 我是在本地环境运行的,play ground 会死锁,但是本地没有
|
4
codehz 2022 年 5 月 27 日 via Android
引用 cgo 的包(包括 net )就会关闭死锁检测器
|
5
koujianshusheng OP @codehz 这个说法有参考资料吗,亲
|
6
iBugOne 2022 年 5 月 27 日 via Android
|
7
koujianshusheng OP @iBugOne 感谢
|
8
lysS 2022 年 5 月 27 日
无论是否 import net ,我这里都是 17 没有报错,18 报错
|
9
lysS 2022 年 5 月 27 日
知道了,net 没有 cgo ,可以 import "C"来检测
|
10
zuokanyunqishi 2022 年 5 月 27 日
go1.18.1 复现。。
|