Added upstream from http://ftp.icm.edu.pl/pub/loglan/
[loglan.git] / HTML / MicroMan / coroutin.htm
1 <!doctype html public "-//IETF//DTD HTML//EN">\r
2 <HTML>\r
3 \r
4 <HEAD>\r
5 \r
6 <TITLE>Coroutines and semicoroutines</TITLE>\r
7 \r
8 <META NAME="GENERATOR" CONTENT="Internet Assistant for Word 1.0Z">\r
9 <META NAME="AUTHOR" CONTENT="NOM">\r
10 </HEAD>\r
11 \r
12 <BODY>\r
13 \r
14 <H4><U><I>Loglan 82, A micro-manual of the programming language\r
15 - Basic constructs and facilities</I></U></H4>\r
16 \r
17 <H1><IMG ALIGN=MIDDLE SRC="gifs/logo2.gif"> 7) Coroutines and\r
18 semicoroutines</H1>\r
19 <HR>\r
20 \r
21 <P>\r
22 Coroutine is a generalization of class. A coroutine object is\r
23 an object such that the execution of its sequence of statements\r
24 can be suspended and reactivated in a programmed manner. Consider\r
25 first a simple class with a sequence of statements such that after\r
26 return some non-executed statements remain. The generation of\r
27 its object terminates with the execution of return statement,\r
28 although the object can be later reactivated. If such a class\r
29 is declared as a coroutine, then its objects may be reactivated.\r
30 This can be realized by an attach statement:\r
31 <PRE>\r
32 <B>attach</B>(X)\r
33 </PRE>\r
34 \r
35 <P>\r
36 where X is a reference variable designating the activating coroutine\r
37 object.\r
38 <P>\r
39 In general, since the moment of generation a coroutine object\r
40 is either active or suspended. Any reactivation of a suspended\r
41 coroutine object X (by attach(X)) causes the active coroutine\r
42 object to be suspended and continues the execution of X from the\r
43 statement following the last executed one.\r
44 <P>\r
45 Main program is also a coroutine. It is accessed through the standard\r
46 variable main and may be reactivated (if suspended) by the statement\r
47 attach(main).\r
48 <P>\r
49 Example:\r
50 <P>\r
51 In the example below the cooperation of two coroutines is presented.\r
52 One reads the real values from an input device, another prints\r
53 these values in columns on a line-printer, n numbers in a line.\r
54 The input stream ends with 0.\r
55 <P>\r
56 <IMG SRC="gifs/co02.gif"> \r
57 <P>\r
58 Then\r
59 <P>\r
60 <IMG SRC="gifs/co03.gif"> \r
61 <P>\r
62 In the example below the application of detach statement is illustrated.\r
63 <P>\r
64 Example:\r
65 <P>\r
66 <IMG SRC="gifs/co04.gif"> \r
67 <P>\r
68 Coroutines play the substantial role in process simulation. Class\r
69 Simulation provided in Simula-67 makes use of coroutines at most\r
70 degree. LOGLAN-82 provides for easy simulation as well. The LOGLAN-82\r
71 class Simulation is implemented on a heap what gives lg(n) time\r
72 cost (in contrast with O(n) cost of the original implementation).\r
73 It covers also various simulation problems of large size and degree\r
74 of complexity. <HR>\r
75 <hr>\r
76 <P>\r
77 <A HREF="Adjustab.htm"><IMG SRC="gifs/PrevPage.gif"></A>\r
78 <A HREF="HomePage.htm"><IMG SRC="gifs/HomePage.gif"></A> \r
79 <A HREF="Prefixin.htm"><IMG SRC="gifs/NextPage.gif"></A> <HR>\r
80 \r
81 <ADDRESS>\r
82 Last update 02/07/95 \r
83 </ADDRESS>\r
84 \r
85 <ADDRESS>\r
86 Comments, suggestions and critiques are welcome to : <A HREF="mailto:linfo062@crisv2.univ-pau.fr">linfo062@crisv2.univ-pau.fr</A>\r
87 \r
88 </ADDRESS>\r
89 \r
90 </BODY>\r
91 \r
92 </HTML>\r