golang在死锁检测中有奇怪的行为

Wei*_*Guo 2 go

package main

import (
    "log"
    "net/http"
)

func useless_func(address string) []byte {
    http.Get("https://www.google.com")
    return nil
}
func test_a(test_channel chan int) {
    test_channel <- 1
    return
}

func test() {
    test_channel := make(chan int)
    for i := 0; i < 10; i++ {
        go test_a(test_channel)
    }
    for {
        log.Println(<-test_channel)
    }
}
func main() {
    test()
}
Run Code Online (Sandbox Code Playgroud)

这段代码不会因为死锁而中断,我在Linux 4.1.6-1和3.16.0-4下使用go 1.5.1 amd64尝试此代码并得到相同的结果.但如果我删除useless_func或使用去1.4.3或在Windows下运行它,它会表现良好.这真的很奇怪,如果有人能解释一下吗?

Wei*_*Guo 5

Dominik Honnef 针对Go 1.5.1的问题## 12734提供了答案:

dominikh:问题在于使用cgo(网络使用,忽略细节).使用cgo时,Go死锁检测无法正常运行,因为C world可能随时调用Go函数,因此理论上不存在死锁; 我们可能只是无限期地等待外部函数调用.