typehchanstruct{qcountuint// total data in the queue
dataqsizuint// size of the circular queue
bufunsafe.Pointer// points to an array of dataqsiz elements
elemsizeuint16closeduint32elemtype*_type// element type
sendxuint// send index
recvxuint// receive index
recvqwaitq// list of recv waiters
sendqwaitq// list of send waiters
// lock protects all fields in hchan, as well as several
// fields in sudogs blocked on this channel.
//
// Do not change another G's status while holding this lock
// (in particular, do not ready a G), as this can deadlock
// with stack shrinking.
lockmutex}
// /usr/local/go/src/runtime/chan.go
funcfull(c*hchan)bool{// c.dataqsiz is immutable (never written after the channel is created)
// so it is safe to read at any time during channel operation.
ifc.dataqsiz==0{// Assumes that a pointer read is relaxed-atomic.
returnc.recvq.first==nil}// Assumes that a uint read is relaxed-atomic.
returnc.qcount==c.dataqsiz}