chan.go recv函数的最后一个参数

来源:1-9 神奇的内置数据结构

一只小popo

2021-06-07 21:14:37

if sg := c.sendq.dequeue(); sg != nil {
// Found a waiting sender. If buffer is size 0, receive value
// directly from sender. Otherwise, receive from head of queue
// and add sender's value to the tail of the queue (both map to
// the same buffer slot because the queue is full).
recv(c, sg, ep, func() { unlock(&c.lock) }, 3)
return true, true
}

上面这段代码摘自chan.go,chanrecv函数内对于sendq不为空的情况,请问recv的最后那个3是什么意思

写回答

1回答

Xargin

2021-06-08

这个是给 trace 或者 pprof 的工具用的,

这些工具会记录一些调用栈,但没必要把 runtime 中所有的栈全打印出来(skip 一般指的就是省略几层栈之类的意思),所以中间会跳掉一些


不了解 trace 和 pprof 的话,可以先认为这个参数没啥用

0

Go高级工程师实战营

慕课网与 GoCN 社区官方联手打造,定义行业Go高级人才培养标准,4个月,快速晋升为P6+/D7级高级人才。

458 学习 · 266 问题

查看课程