1、问题
在学习golang网络编码时,阅读到poll_runtime_pollWait函数,发现此函数如果在没有I/O事件(读写DeadTime设置较大时)会陷入死循环,直到I/O事件到来,这样会造成巨大的cpu浪费,但是实际使用中没有观察到cpu突升的情况,是不是我哪里遗漏了或者理解有问题? 求大神指点一下。
2、函数调用时序
func (c *conn) Read(b []byte) func (fd *netFD) Read(p []byte) func (fd *FD) Read(p []byte) func (pd *pollDesc) waitRead(isFile bool) func (pd *pollDesc) wait(mode int, isFile bool) func runtime_pollWait(ctx uintptr, mode int) func poll_runtime_pollWait(pd *pollDesc, mode int)
3、golang源码
net/net.go
// Read implements the Conn Read method.
func (c *conn) Read(b []byte) (int, error) {
if !c.ok() {
return 0, syscall.EINVAL
}
n, err := c.fd.Read(b)
if err != nil && err != io.EOF {
err = &OpError{Op: "read", Net: c.fd.net, Source: c.fd.laddr, Addr: c.fd.raddr, Err: err}
}
return n, err
}
net/fd_posix.go