Why doesn't this code return a “deadlock” error?

萝らか妹 提交于 2020-12-25 14:30:10

问题


package main

import (
    "fmt"
    "net/http"
)

func Extract(url string) ([]string, error) {
    http.Get(url)

    var links []string
    return links, nil
}

func crawl(url string) []string {
    list, _ := Extract(url)
    return list
}

func main() {
    var ch = make(chan int)
    ch <- 1
}

If I remove the net/http import, it will return a "deadlock" error as expected. But if I import this package, although I didn't invoke the Extract func, the "deadlock" will not appear.


回答1:


Importing the net package starts background polling Goroutines that effectively disable the deadlock detector.

You can see the discussion for a similar issue here: https://github.com/golang/go/issues/12734



来源:https://stackoverflow.com/questions/58619289/why-doesnt-this-code-return-a-deadlock-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!