学习golang的时候libtask库的代码是一定要看的,需要深入理解chan和携程的运行机制,下面就结合libtask的源码说明下运行原理,如果理解的有偏差欢迎指正
下面是libtask中Channel的结构
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;
};