libtask channel机理及调度理解
学习golang的时候libtask库的代码是一定要看的,需要深入理解chan和携程的运行机制,下面就结合libtask的源码说明下运行原理,如果理解的有偏差欢迎指正
下面是libtask中Channel的结构
1 struct Alt 2 { 3 Channel *c; 4 void *v; 5 unsigned int op; 6 Task *task; 7 Alt *xalt; 8 }; 9 10 struct Altarray 11 { 12 Alt **a; 13 unsigned int n; 14 unsigned int m; 15 }; 16 17 struct Channel 18 { 19 unsigned int bufsize; 20 unsigned int elemsize; 21 unsigned char *buf; 22 unsigned int nbuf; 23 unsigned int off; 24 Altarray asend; 25 Altarray arecv; 26 char *name; 27 };