作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我收到以下错误,我不明白为什么:
发送:查询 Herefatal 错误:所有 goroutines 都睡着了 - 死锁!
您可以看到我正在调用我使用 goroutine 创建的函数 routine
。我真的没有更多细节可以提供。
package main
import (
"fmt"
"net"
"sync"
)
const (
udphost = "127.0.0.1"
udpport = ":150"
StopCharacter = "\r\n\r\n"
)
var wg sync.WaitGroup
func routine() {
defer wg.Done()
// establish connection address parts
schemaUri := udphost + udpport
udpAddr, err := net.ResolveUDPAddr("udp4", schemaUri)
// make connection
conn, err := net.DialUDP("udp", nil, udpAddr)
fmt.Printf("%v", conn)
// defer close
defer conn.Close()
// handle connection errors
if err != nil {
fmt.Println("Erorr Establishing UDP Connection")
return
}
// input query
message := "Query Here"
// Write query to server
conn.Write([]byte(message))
conn.Write([]byte(StopCharacter))
fmt.Printf("Send: %s", message)
// Read response from server
buffr := make([]byte, 1024)
buffw := make([]byte, 1024)
n, _, _, _, _ := conn.ReadMsgUDP(buffr, buffw)
fmt.Printf("Receive: %s", n)
// parse message
msg := string(buffr[0:n])
fmt.Println(msg)
}
func main() {
wg.Add(1)
go routine()
wg.Wait()
}
最佳答案
尝试
func main(){
var wg &sync.WaitGroup
wg.Add(1)
go routine(wg)
...
wg.Wait()
}
func routine(wg *sync.WaitGroup){
...
defer wg.Done()
}
关于go - 反正执行 goroutine 时所有 goroutines 都睡着了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50702463/
我在执行一个Gradle任务时遇到此错误。 :46:52 * Where: 14:46:52 Initialization script '/production/builds/jenkins_sla
我是一名优秀的程序员,十分优秀!