By cszhao1980
本章将探讨unix v6代码中最微妙的部分,即著名的注释:“ You are not expected to understand this”。
2178: swtch()
2179: {
2180: static struct proc *p;
2181: register i, n;
2182: register struct proc *rp;
……
2228: retu(rp->p_addr);
2229: sureg();
2230: /*
2231: * If the new process paused because it was
2232: * swapped out, set the stack level to the last call
2233: * to savu(u_ssav). This means that the return
2234: * which is executed immediately after the call to aretu
2235: * actually returns from the last routine which did
2236: * the savu.
2237: *
2238: * You are not expected to understand this.
2239: */
2240: if(rp->p_flag&SSWAP) {
2241: rp->p_flag =& ~SSWAP;
2242: aretu(u.u_ssav);
2243: }
2244: /* The value returned here has many subtle implications.
2245: * See the newproc comments.
2246: */
2247: return(1);
2248: }
相关代码仅有三行,逻辑非常简单:
(1) 在swtch()退出之前,会检查进程的<