This is a creation in Article, where the information may have evolved or changed. "Go Language Programming" introduces the Libtask library, you can think of this library as equivalent to the bottom goroutine implementation of go. of the Libtask library The channel data structure is as follows:
struct Alt
{
Channel *c;
void *v;
unsigned int op;
Task *task;
Alt *xalt;
};
struct Altarray
{
Alt **a;
unsigned int n;
unsigned int m;
};
struct Channel
{
unsigned int bufsize;
unsigned int elemsize;
unsigned char *buf;
unsigned int nbuf;
unsigned int off;
Altarray asend;
Altarray arecv;
char *name;
};
We can see that the basic composition of the channel is as follows: Memory cache, for storing elements, sending queue, accepting queue.
The book lists the channel structure without in-depth explanation of how to communicate on the channel structure. In fact, combined with the contents of the book described in the previous Task (association) of the communication process has been made clear. But from the learner's point of view, of course, the more you explain the problem, the better. Next I try to explain how the task (coprocessor) communicates on this channel basis. For a situation where data is written to the channel:
For a situation where the data is read from the channel:
Note: The above two processes are based on the work principle of the association and the channel data structure after the introduction of my personal brain complement, and did not go through the Libtask code. There is a good chance that these two processes should be used as a reference to understand how the process works.
From for notes (Wiz)