Added upstream from http://ftp.icm.edu.pl/pub/loglan/
[loglan.git] / HTML / MicroMan / Concurre.htm
1 <!doctype html public "-//IETF//DTD HTML//EN">\r
2 <HTML>\r
3 \r
4 <HEAD>\r
5 \r
6 <TITLE>Concurrent processes</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 <P>\r
15 <U><I>Loglan 82, A micro-manual of the programming language -\r
16 Basic constructs and facilities</I></U>\r
17 <H1><IMG ALIGN=MIDDLE SRC="gifs/logo2.gif"> 13) Concurrent processes\r
18 </H1>\r
19 <HR>\r
20 \r
21 <P>\r
22 Loglan allows to create and execute objects-processes. They can\r
23 operate simultaneously on different computers linked into a LAN\r
24 network or a few processes can share one processor (its time-slices).\r
25 <P>\r
26 Process modules are different from the classes and coroutines\r
27 for, they use the keyword process. The syntax of process modules\r
28 is otherwise the same. In a process one can use a few more instructions:\r
29 resume (resume a process which is passive), stop - make the current\r
30 process passive, etc.\r
31 <P>\r
32 All processes (even those executed on the same computer) are implemented\r
33 as distributed, i.e. without any shared memory. This fact implies\r
34 some restrictions on how processes may be used. Not all restrictions\r
35 are enforced by the present compiler, so it is the programmer's\r
36 responsibility to respect them. For the details see the User's\r
37 Manual.\r
38 <P>\r
39 Semantics of the generator <B>new</B> is slightly modified when\r
40 applied to the processes. The first parameter of the first process\r
41 unit in the prefix sequence must be of type INTEGER. This parameter\r
42 denotes the node number of the computer on which this process\r
43 will be created. For a single computer operation this parameter\r
44 must be equal to 0.\r
45 <P>\r
46 Example:\r
47 <P>\r
48 <IMG SRC="gifs/cp01.gif"> \r
49 <P>\r
50 COMMUNICATION MECHANISM\r
51 <P>\r
52 Processes may communicate and synchronize by a mechanism based\r
53 on rendez-vous. It will be referred to as &quot;alien call&quot;\r
54 in the following description.\r
55 <P>\r
56 An alien call is either:\r
57 <UL>\r
58 <LI>a procedure call performed by a remote access to a process\r
59 object, or\r
60 <LI>a call of a procedure which is a formal parameter of a process,\r
61 or\r
62 <LI>a call of a procedure which is a formal parameter of an alien-called\r
63 procedure (this is a recursive definition).\r
64 </UL>\r
65 \r
66 <P>\r
67 Every process object has an enable mask. It is defined as a subset\r
68 of all procedures declared directly inside a process unit or any\r
69 unit from its prefix sequence (i.e. subset of all procedures that\r
70 may be alien-called).\r
71 <P>\r
72 A procedure is enabled in a process if it belongs to that process'\r
73 enable mask. A procedure is disabled if it does not belong to\r
74 the enable mask.\r
75 <P>\r
76 Immediately after generation of a process object its enable mask\r
77 is empty (all procedures are disabled).\r
78 <P>\r
79 Semantics of the alien call is different from the remote call\r
80 described in the report. Both the calling process and the process\r
81 in which the procedure is declared (i.e. the called process) are\r
82 involved in the alien call. This way the alien call may be used\r
83 as a synchronization mechanism.\r
84 <P>\r
85 The calling process passes the input parameters and waits for\r
86 the call to be completed.\r
87 <P>\r
88 The alien-called procedure is executed by the called process.\r
89 Execution of the procedure will not begin before certain conditions\r
90 are satisfied. First, the called process must not be suspended\r
91 in any way. The only exception is that it may be waiting during\r
92 the ACCEPT statement (see below). Second, the procedure must be\r
93 enabled in the called process.\r
94 <P>\r
95 When the above two conditions are met the called process is interrupted\r
96 and forced to execute the alien-called procedure (with parameters\r
97 passed by the calling process).\r
98 <P>\r
99 Upon entry to the alien-called procedure all procedures become\r
100 disabled in the called process.\r
101 <P>\r
102 Upon exit the enable mask of the called process is restored to\r
103 that from before the call (regardless of how it has been changed\r
104 during the execution of the procedure). The called process is\r
105 resumed at the point of the interruption. The execution of the\r
106 ACCEPT statement is ended if the called process was waiting during\r
107 the ACCEPT (see below). At last the calling process reads back\r
108 the output parameters and resumes its execution after the call\r
109 statement.\r
110 <P>\r
111 The process executing an alien-called procedure can easily be\r
112 interrupted by another alien call if the enable mask is changed.\r
113 <P>\r
114 There are some new language constructs associated with the alien\r
115 call mechanism. The following statements change the enable mask\r
116 of a process:\r
117 <P>\r
118 <IMG SRC="gifs/cp02.gif"> \r
119 <P>\r
120 enables the procedures with identifiers p1, ..., pn. If there\r
121 are any processes waiting for an alien call of one of these procedures,\r
122 one of them is chosen and its request is processed. The scheduling\r
123 is done on a FIFO basis, so it is strongly fair. The statement:\r
124 <P>\r
125 <IMG SRC="gifs/cp03.gif"> \r
126 <P>\r
127 disables the procedures with identifiers p1, ..., pn.\r
128 <P>\r
129 In addition a special form of the RETURN statement:\r
130 <P>\r
131 <IMG SRC="gifs/cp04.gif"> \r
132 <P>\r
133 allows to enable the procedures p1, ..., pn and disable the procedures\r
134 q1,...,qn after the enable mask is restored on exit from the alien-called\r
135 procedure. It is legal only in the alien-called procedures (the\r
136 legality is not enforced by the compiler).\r
137 <P>\r
138 A called process may avoid busy waiting for an alien call by means\r
139 of the ACCEPT statement:\r
140 <P>\r
141 <IMG SRC="gifs/cp05.gif"> \r
142 <P>\r
143 adds the procedures p1, ..., pn to the current mask, and waits\r
144 for an alien call of one of the currently enabled procedures.\r
145 After the procedure return the enable mask is restored to that\r
146 from before the ACCEPT statement.\r
147 <P>\r
148 Note that the ACCEPT statement alone (i.e. without any ENABLE/DISABLE\r
149 statements or options) provides a sufficient communication mechanism.\r
150 In this case the called process may execute the alien-called procedure\r
151 only during the ACCEPT statement (because otherwise all procedures\r
152 are disabled). It means that the enable mask may be forgotten\r
153 altogether and the alien call may be used as a pure totally synchronous\r
154 rendez-vous. Other constructs are introduced to make partially\r
155 asynchronous communication patterns possible.\r
156 <P>\r
157 Below find a complete listing of a simple example - monitors.\r
158 <P>\r
159 <IMG SRC="gifs/cp06.gif"> <HR>\r
160 <hr>\r
161 <P>\r
162 <A HREF="Exceptio.htm"><IMG SRC="gifs/PrevPage.gif"></A>\r
163 <A HREF="HomePage.htm"><IMG SRC="gifs/HomePage.gif"></A> \r
164 <A HREF="Referenc.htm"><IMG SRC="gifs/NextPage.gif"></A> <HR>\r
165 \r
166 <ADDRESS>\r
167 Last update 02/07/95 \r
168 </ADDRESS>\r
169 \r
170 <ADDRESS>\r
171 Comments, suggestions and critiques are welcome to : <A HREF="mailto:linfo062@crisv2.univ-pau.fr">linfo062@crisv2.univ-pau.fr</A>\r
172 \r
173 </ADDRESS>\r
174 \r
175 </BODY>\r
176 \r
177 </HTML>\r