March 2020
Intermediate to advanced
406 pages
8h 39m
English
Channels are invoked using the make() Golang built-in, where an hchan struct is created. The hchan struct contains a count of the data in the queue, the size of the queue, an array pointer for the buffer, send and receive indices and waiters, and a mutex lock. The following code block illustrates this:
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 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 ...Read now
Unlock full access