channel
目录
chansend, chanrec, closechan 的结果
-
黄色标记为返回值
1 2 3 4 5 6 7 8 9
// chanrecv 有两个 bool 返回值 selected received // 例如: // select { // case v, ok =<- c: // ... // } // selected : 表示 case 可以被 selected // received : ok == true func chanrecv(c *hchan, ep unsafe.Pointer, block bool) (selected, received bool) {}
-
block : blocking IO, 取决于是否有 default case
-
1 2 3 4 5 6
func full(c *hchan) bool { if c.dataqsiz == 0 { return c.recvq.first == nil } return c.qcount == c.dataqsiz }
-
1 2 3 4 5 6
func empty(c *hchan) bool { if c.dataqsiz == 0 { return atomic.Loadp(unsafe.Pointer(&c.sendq.first)) == nil } return atomic.Loaduint(&c.qcount) == 0 }
源码
runtime/chan.go
|
|
语法糖
|
|