⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cr.7

📁 UNIX v6源代码 这几乎是最经典的unix版本 unix操作系统设计和莱昂氏unix源代码分析都是用的该版
💻 7
字号:
.th CR VII 1/4/75.sh NAMEcrfork, crexit, crread, crwrite, crexch, crprior \*- coroutine scheme.sh SYNOPSIS.nf.ft Bint crfork( \fR[\fB stack, nwords \fR]\fB )int stack[];int nwords;.s3crexit().s3int crread(connector, buffer, nbytes)int *connector[2];char *buffer;int nbytes;.s3crwrite(connector, buffer, nbytes)int *connector[2];char *buffer;int nbytes;.s3crexch(conn1, conn2, i)int *conn1[2], *conn2[2];int i;.s3#define logical char *crprior(p)logical p;.fi.ft R.sh DESCRIPTIONThese functions are named by analogy to.it "fork, exit, read, write"(II).They establish and synchronize `coroutines', whichbehave in many respects like a set of processes workingin the same address space.The functions live in.it /usr/lib/cr.a..s3Coroutines are placedon queues to indicate their state of readiness.One coroutine is always distinguished as `running'.Coroutines that are runnable but not runningare registered on a `ready queue'.The head member of the ready queue is started whenever no othercoroutine is specifically caused to be running..s3Each connector heads twoqueues: .it Connector[0]is the queue of unsatisfied .it crreadsoutstanding on the connector..it Connector[1]is the queue of.it crwrites.All queues must start empty,.it i.e.with heads set to zero..s3.it Crforkis normally called with no arguments.Itplaces the running coroutine at the head ofthe ready queue, creates a new coroutine, and starts the new one running..it Crforkreturns immediately in the new coroutine with value 0,and upon restarting of the oldcoroutine with value 1..s3.it Crexitstops the running coroutine and does not place it in any queue..s3.it Crreadcopies characters from the.it bufferof the .it crwriteat the head of the .it connector'swrite queue to the .it bufferof.it crread.If the write queue is empty, copying is delayed and the runningcoroutine is placed on the read queue.The number of characters copied is the minimum of.it nbytesand the number of characters remaining in the write.it buffer,and is returned as the value of.it crread.After copying, the location of the write.it bufferand the corresponding.it nbytesare updated appropriately.If zero characters remain, the coroutine of the.it crwriteis moved to the head of the ready queue.If the write queue remains nonempty,the head member of the read queue is moved tothe head of the ready queue..s3.it Crwritequeues the running coroutine on the.it connector'swrite queue,and records the fact that.it nbytes(zero or more)characters in the string.it bufferare available to .it crreads.If the read queue is not empty,its head member is started running..s3.it Crexchexchanges the read queues of connectors.it conn1and.it conn2if\fIi\fR=0; and it exchanges the write queues if\fIi\fR=1.If a nonempty read queue that had been paired with an empty write queuebecomes paired with a nonempty write queue,.it crexchmovesthe head member of that read queue to the headof the ready queue..s3.it Crpriorsets a priority on the running coroutine to control the queuing of.it crreadsand.it crwrites.When queued, the running coroutine will take its place beforecoroutines whose priorities exceedits own priority and after others.Priorities are compared as logical,.it i.e.unsigned,quantities.Initially each coroutine's priority is set as large as possible,so default queuing is.nhFIFO..hy.s3.bd "Storage allocation."The old and new coroutine share the same activation recordin the function that invoked.it crfork,so only one may return from the invoking function,and then only when the other has completed execution in that function..s3The activation record for each functionexecution is dynamically allocated rather than stacked;a factor of 3 in running time overheadcan result if function calls are very frequent.The overhead may be overcome byproviding a separate stack for each coroutine and dispensing withdynamic allocation.The base (lowest) address and size of thenew coroutine's stack are supplied to.it crforkas optional arguments.it stackand.it nwords.Stacked allocation and dynamic allocation cannot be mixedin one run.For stacked operation, obtain the coroutine functions from.it /usr/lib/scr.ainstead of.it /usr/lib/cr.a..sh FILES/usr/lib/cr.a.br/usr/lib/scr.a.sh DIAGNOSTICS`rsave doesn't work' \*- an old C compilationhas called `rsave'.It must be recompiled to workwith the coroutine scheme..sh BUGSUnder /usr/lib/cr.aeach function has just 12 words of anonymousstack for hard expressions and argumentsof further calls, regardless of actual need.There is no checking for stack overflow..brUnder /usr/lib/scr.astack overflow checking is not rigorous.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -