结构体
type hchan struct { qcount uint // total data in the queue dataqsiz uint // size of the circular queue buf unsafe.Pointer // points to an array of dataqsiz elements elemsize uint16 closed uint32 //状态值 0未开启,1为关闭 elemtype *_type // element type sendx uint // send index recvx uint // receive index recvq waitq // list of recv waiters 接收队列 sendq waitq // 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. lock mutex // 互斥锁并不是排队发送/接收数据 // 互斥锁保护的hchan结构体本身 // channel并不是无锁的}
发送数据的底层原理

直接发送
放入缓存

休眠等待

总结
