home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V6 / usr / man / man7 / cr.7 next >
Encoding:
Text File  |  1975-06-26  |  4.7 KB  |  201 lines

  1. .th CR VII 1/4/75
  2. .sh NAME
  3. crfork, crexit, crread, crwrite, crexch, crprior \*- coroutine scheme
  4. .sh SYNOPSIS
  5. .nf
  6. .ft B
  7. int crfork( \fR[\fB stack, nwords \fR]\fB )
  8. int stack[];
  9. int nwords;
  10. .s3
  11. crexit()
  12. .s3
  13. int crread(connector, buffer, nbytes)
  14. int *connector[2];
  15. char *buffer;
  16. int nbytes;
  17. .s3
  18. crwrite(connector, buffer, nbytes)
  19. int *connector[2];
  20. char *buffer;
  21. int nbytes;
  22. .s3
  23. crexch(conn1, conn2, i)
  24. int *conn1[2], *conn2[2];
  25. int i;
  26. .s3
  27. #define logical char *
  28. crprior(p)
  29. logical p;
  30. .fi
  31. .ft R
  32. .sh DESCRIPTION
  33. These functions are named by analogy to
  34. .it "fork, exit, read, write"
  35. (II).
  36. They establish and synchronize `coroutines', which
  37. behave in many respects like a set of processes working
  38. in the same address space.
  39. The functions live in
  40. .it /usr/lib/cr.a.
  41. .s3
  42. Coroutines are placed
  43. on queues to indicate their state of readiness.
  44. One coroutine is always distinguished as `running'.
  45. Coroutines that are runnable but not running
  46. are registered on a `ready queue'.
  47. The head member of the ready queue is started whenever no other
  48. coroutine is specifically caused to be running.
  49. .s3
  50. Each connector heads two
  51. queues: 
  52. .it Connector[0]
  53. is the queue of unsatisfied 
  54. .it crreads
  55. outstanding on the connector.
  56. .it Connector[1]
  57. is the queue of
  58. .it crwrites.
  59. All queues must start empty,
  60. .it i.e.
  61. with heads set to zero.
  62. .s3
  63. .it Crfork
  64. is normally called with no arguments.
  65. It
  66. places the running coroutine at the head of
  67. the ready queue, creates a new coroutine, and starts the new 
  68. one running.
  69. .it Crfork
  70. returns immediately in the new coroutine with value 0,
  71. and upon restarting of the old
  72. coroutine with value 1.
  73. .s3
  74. .it Crexit
  75. stops the running coroutine and does not place it in any queue.
  76. .s3
  77. .it Crread
  78. copies characters from the
  79. .it buffer
  80. of the 
  81. .it crwrite
  82. at the head of the 
  83. .it connector's
  84. write queue to the 
  85. .it buffer
  86. of
  87. .it crread.
  88. If the write queue is empty, copying is delayed and the running
  89. coroutine is placed on the read queue.
  90. The number of characters copied is the minimum of
  91. .it nbytes
  92. and the number of characters remaining in the write
  93. .it buffer,
  94. and is returned as the value of
  95. .it crread.
  96. After copying, the location of the write
  97. .it buffer
  98. and the corresponding
  99. .it nbytes
  100. are updated appropriately.
  101. If zero characters remain, the coroutine of the
  102. .it crwrite
  103. is moved to the head of the ready queue.
  104. If the write queue remains nonempty,
  105. the head member of the read queue is moved to
  106. the head of the ready queue.
  107. .s3
  108. .it Crwrite
  109. queues the running coroutine on the
  110. .it connector's
  111. write queue,
  112. and records the fact that
  113. .it nbytes
  114. (zero or more)
  115. characters in the string
  116. .it buffer
  117. are available to 
  118. .it crreads.
  119. If the read queue is not empty,
  120. its head member is started running.
  121. .s3
  122. .it Crexch
  123. exchanges the read queues of connectors
  124. .it conn1
  125. and
  126. .it conn2
  127. if
  128. \fIi\fR=0; and it exchanges the write queues if
  129. \fIi\fR=1.
  130. If a nonempty read queue that had been paired with an empty write queue
  131. becomes paired with a nonempty write queue,
  132. .it crexch
  133. moves
  134. the head member of that read queue to the head
  135. of the ready queue.
  136. .s3
  137. .it Crprior
  138. sets a priority on the running coroutine to 
  139. control the queuing of
  140. .it crreads
  141. and
  142. .it crwrites.
  143. When queued, the running coroutine will take its place before
  144. coroutines whose priorities exceed
  145. its own priority and after others.
  146. Priorities are compared as logical,
  147. .it i.e.
  148. unsigned,
  149. quantities.
  150. Initially each coroutine's priority is set as large as possible,
  151. so default queuing is
  152. .nh
  153. FIFO.
  154. .hy
  155. .s3
  156. .bd "Storage allocation."
  157. The old and new coroutine share the same activation record
  158. in the function that invoked
  159. .it crfork,
  160. so only one may return from the invoking function,
  161. and then only when the other has completed execution in that function.
  162. .s3
  163. The activation record for each function
  164. execution is dynamically allocated rather than stacked;
  165. a factor of 3 in running time overhead
  166. can result if function calls are very frequent.
  167. The overhead may be overcome by
  168. providing a separate stack for each coroutine and dispensing with
  169. dynamic allocation.
  170. The base (lowest) address and size of the
  171. new coroutine's stack are supplied to
  172. .it crfork
  173. as optional arguments
  174. .it stack
  175. and
  176. .it nwords.
  177. Stacked allocation and dynamic allocation cannot be mixed
  178. in one run.
  179. For stacked operation, obtain the coroutine functions from
  180. .it /usr/lib/scr.a
  181. instead of
  182. .it /usr/lib/cr.a.
  183. .sh FILES
  184. /usr/lib/cr.a
  185. .br
  186. /usr/lib/scr.a
  187. .sh DIAGNOSTICS
  188. `rsave doesn't work' \*- an old C compilation
  189. has called `rsave'.
  190. It must be recompiled to work
  191. with the coroutine scheme.
  192. .sh BUGS
  193. Under /usr/lib/cr.a
  194. each function has just 12 words of anonymous
  195. stack for hard expressions and arguments
  196. of further calls, regardless of actual need.
  197. There is no checking for stack overflow.
  198. .br
  199. Under /usr/lib/scr.a
  200. stack overflow checking is not rigorous.
  201.