1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Latex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
2 | %% |
---|
3 | %% Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo |
---|
4 | %% |
---|
5 | %% The contents of this file are covered under the licence agreement in the |
---|
6 | %% file "LICENCE" distributed with Cforall. |
---|
7 | %% |
---|
8 | %% user.tex -- |
---|
9 | %% |
---|
10 | %% Author : Peter A. Buhr |
---|
11 | %% Created On : Wed Apr 6 14:53:29 2016 |
---|
12 | %% Last Modified By : Peter A. Buhr |
---|
13 | %% Last Modified On : Sun Sep 17 09:10:12 2023 |
---|
14 | %% Update Count : 5883 |
---|
15 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
16 | |
---|
17 | % requires tex packages: texlive-base texlive-latex-base tex-common texlive-humanities texlive-latex-extra texlive-fonts-recommended |
---|
18 | |
---|
19 | \documentclass[11pt]{article} |
---|
20 | |
---|
21 | \makeatletter |
---|
22 | \def\@maketitle{% |
---|
23 | \newpage |
---|
24 | \null |
---|
25 | % \vskip 2em% |
---|
26 | \begin{center}% |
---|
27 | \let \footnote \thanks |
---|
28 | {\LARGE\bf \@title \par}% |
---|
29 | \@ifundefined{@author}{} |
---|
30 | { |
---|
31 | \ifx\@empty\@author |
---|
32 | \else |
---|
33 | \vskip 1.5em% |
---|
34 | {\large |
---|
35 | \lineskip .5em% |
---|
36 | \begin{tabular}[t]{c}% |
---|
37 | \@author |
---|
38 | \end{tabular}% |
---|
39 | \par |
---|
40 | }% |
---|
41 | \fi |
---|
42 | }% |
---|
43 | \ifx\@empty\@date |
---|
44 | \else |
---|
45 | \vskip 1em% |
---|
46 | {\large \@date}% |
---|
47 | \fi |
---|
48 | \end{center}% |
---|
49 | \par |
---|
50 | % \vskip 1.5em |
---|
51 | }%maketitle |
---|
52 | \makeatother |
---|
53 | |
---|
54 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
55 | |
---|
56 | % Latex packages used in the document. |
---|
57 | %\usepackage[T1]{fontenc} % allow Latin1 (extended ASCII) characters |
---|
58 | %\usepackage{textcomp} |
---|
59 | %\usepackage[latin1]{inputenc} |
---|
60 | |
---|
61 | \usepackage{fullpage,times,comment} |
---|
62 | \usepackage{epic,eepic} |
---|
63 | \usepackage{upquote} % switch curled `'" to straight |
---|
64 | \usepackage[labelformat=simple,aboveskip=0pt,farskip=0pt]{subfig} |
---|
65 | \renewcommand{\thesubfigure}{\alph{subfigure})} |
---|
66 | \usepackage{latexsym} % \Box glyph |
---|
67 | \usepackage{mathptmx} % better math font with "times" |
---|
68 | \usepackage[usenames]{color} |
---|
69 | \usepackage[pagewise]{lineno} |
---|
70 | \renewcommand{\linenumberfont}{\scriptsize\sffamily} |
---|
71 | \input{common} % common CFA document macros |
---|
72 | \usepackage[dvips,plainpages=false,pdfpagelabels,pdfpagemode=UseNone,colorlinks=true,pagebackref=true,linkcolor=blue,citecolor=blue,urlcolor=blue,pagebackref=true,breaklinks=true]{hyperref} |
---|
73 | \usepackage{breakurl} |
---|
74 | |
---|
75 | \renewcommand\footnoterule{\kern -3pt\rule{0.3\linewidth}{0.15pt}\kern 2pt} |
---|
76 | \newcommand{\uC}{$\mu$\CC} |
---|
77 | |
---|
78 | % Default underscore is too low and wide. Cannot use lstlisting "literate" as replacing underscore |
---|
79 | % removes it as a variable-name character so keywords in variables are highlighted. MUST APPEAR |
---|
80 | % AFTER HYPERREF. |
---|
81 | \renewcommand{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}} |
---|
82 | |
---|
83 | \setlength{\topmargin}{-0.45in} % move running title into header |
---|
84 | \setlength{\headsep}{0.25in} |
---|
85 | |
---|
86 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
87 | |
---|
88 | \setlength{\gcolumnposn}{3in} |
---|
89 | \CFAStyle % use default CFA format-style |
---|
90 | \lstset{language=CFA} % CFA default lnaguage |
---|
91 | \lstnewenvironment{C++}[1][] % use C++ style |
---|
92 | {\lstset{language=C++,escapechar=\$,mathescape=false,moredelim=**[is][\protect\color{red}]{@}{@},#1}}{} |
---|
93 | \lstnewenvironment{uC++}[1][] |
---|
94 | {\lstset{language=uC++,escapechar=\$,mathescape=false,moredelim=**[is][\protect\color{red}]{@}{@},#1}}{} |
---|
95 | |
---|
96 | \newsavebox{\myboxA} |
---|
97 | \newsavebox{\myboxB} |
---|
98 | |
---|
99 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
100 | |
---|
101 | % Names used in the document. |
---|
102 | \newcommand{\Version}{\input{build/version}} |
---|
103 | \newcommand{\Textbf}[2][red]{{\color{#1}{\textbf{#2}}}} |
---|
104 | \newcommand{\Emph}[2][red]{{\color{#1}\textbf{\emph{#2}}}} |
---|
105 | \newcommand{\R}[1]{{\color{red}#1}} |
---|
106 | \newcommand{\RB}[1]{\Textbf{#1}} |
---|
107 | \newcommand{\B}[1]{{\Textbf[blue]{#1}}} |
---|
108 | \newcommand{\G}[1]{{\Textbf[OliveGreen]{#1}}} |
---|
109 | \newcommand{\Sp}{\R{\textvisiblespace}} |
---|
110 | \newcommand{\KWC}{K-W C\xspace} |
---|
111 | |
---|
112 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
113 | |
---|
114 | \setcounter{secnumdepth}{3} % number subsubsections |
---|
115 | \setcounter{tocdepth}{3} % subsubsections in table of contents |
---|
116 | \makeindex |
---|
117 | |
---|
118 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
119 | |
---|
120 | \title{\vspace*{-0.5in} |
---|
121 | \CC/\uC to \CFA Cheat Sheet} |
---|
122 | %\author{Peter A. Buhr} |
---|
123 | \date{} |
---|
124 | |
---|
125 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
126 | |
---|
127 | \begin{document} |
---|
128 | \pagestyle{headings} |
---|
129 | % changed after setting pagestyle |
---|
130 | \renewcommand{\sectionmark}[1]{\markboth{\thesection\quad #1}{\thesection\quad #1}} |
---|
131 | \renewcommand{\subsectionmark}[1]{\markboth{\thesubsection\quad #1}{\thesubsection\quad #1}} |
---|
132 | |
---|
133 | %\linenumbers % comment out to turn off line numbering |
---|
134 | |
---|
135 | \maketitle |
---|
136 | \vspace*{-0.55in} |
---|
137 | |
---|
138 | \section{Introduction} |
---|
139 | |
---|
140 | \CFA is NOT an object-oriented programming-language. |
---|
141 | \CFA uses parametric polymorphism and allows overloading of variables and routines: |
---|
142 | \begin{cfa} |
---|
143 | int i; char i; double i; // overload name i |
---|
144 | int i(); double i(); char i(); |
---|
145 | i += 1; $\C[1.5in]{// int i}$ |
---|
146 | i += 1.0; $\C{// double i}$ |
---|
147 | i += 'a'; $\C{// char i}$ |
---|
148 | int j = i(); $\C{// int i()}$ |
---|
149 | double j = i(); $\C{// double i();}$ |
---|
150 | char j = i(); $\C{// char i()}\CRT$ |
---|
151 | \end{cfa} |
---|
152 | \CFA has rebindable references. |
---|
153 | |
---|
154 | \begin{cquote} |
---|
155 | \begin{tabular}{l|l} |
---|
156 | \multicolumn{2}{l}{\lstinline{ int x = 1, y = 2, * p1x = &x, * p1y = &y, ** p2i = &p1x,}} \\ |
---|
157 | \multicolumn{2}{l}{\lstinline{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ && r1x = x, & r1y = y, && r2i = r1x;}} \\ |
---|
158 | \begin{uC++} |
---|
159 | **p2i = 3; |
---|
160 | p2i = &p1y; |
---|
161 | **p2i = 3; |
---|
162 | p1x = p1y; |
---|
163 | **p2i = 4; |
---|
164 | p1x = @nullptr@; |
---|
165 | \end{uC++} |
---|
166 | & |
---|
167 | \begin{cfa} |
---|
168 | r2i = 3; $\C[1.0in]{// change x}$ |
---|
169 | &r2i = &r1y; $\C{// change p2i / r2i}$ |
---|
170 | r2i = 3; $\C{// change y}$ |
---|
171 | &r1x = &r1y; $\C{// change p1x / r1x}$ |
---|
172 | r2i = 4; $\C{// change y}$ |
---|
173 | &r1x = @0p@; $\C{// reset}\CRT$ |
---|
174 | \end{cfa} |
---|
175 | \end{tabular} |
---|
176 | \end{cquote} |
---|
177 | Non-rebindable reference (\CC reference) is a @const@ reference (@const@ pointer). |
---|
178 | \begin{cfa} |
---|
179 | int & @const@ cr = x; // must initialize, no null pointer |
---|
180 | int & @const@ & @const@ crcr = cr; // generalize |
---|
181 | \end{cfa} |
---|
182 | Aggregate qualification is reduced or eliminated by opening scopes using the @with@ clause. |
---|
183 | \begin{cfa} |
---|
184 | struct S { int i; int j; double m; }; // field i has same type in structures S and T |
---|
185 | struct T { int i; int k; int m; }; |
---|
186 | void foo( S s, T t ) @with(s, t)@ { // open structure scope s and t in parallel |
---|
187 | j + k; $\C[1.6in]{// unambiguous, s.j + t.k}$ |
---|
188 | m = 5.0; $\C{// unambiguous, s.m = 5.0}$ |
---|
189 | m = 1; $\C{// unambiguous, t.m = 1}$ |
---|
190 | int a = m; $\C{// unambiguous, a = t.m}$ |
---|
191 | double b = m; $\C{// unambiguous, b = s.m}$ |
---|
192 | int c = s.i + t.i; $\C{// unambiguous with qualification}$ |
---|
193 | (double)m; $\C{// unambiguous with cast s.m}\CRT$ |
---|
194 | } |
---|
195 | \end{cfa} |
---|
196 | \noindent |
---|
197 | In subsequent code examples, the left example is \CC/\uC and the right example is \CFA. |
---|
198 | |
---|
199 | |
---|
200 | \section{Looping} |
---|
201 | |
---|
202 | \begin{cquote} |
---|
203 | \begin{tabular}{l|l} |
---|
204 | \begin{uC++} |
---|
205 | for ( ;; ) { ... } / while ( true ) { ... } |
---|
206 | for ( int i = 0; i < 10; i += 1 ) { ... } |
---|
207 | for ( int i = 5; i < 15; i += 2 ) { ... } |
---|
208 | int i = 0 |
---|
209 | for ( i = 0; i < 10; i += 1 ) { ... } |
---|
210 | if ( i == 10 ) { ... } |
---|
211 | \end{uC++} |
---|
212 | & |
---|
213 | \begin{cfa} |
---|
214 | for () { ... } / while () { ... } |
---|
215 | for ( 10 ) { ... } / for ( i; 10 ) { ... } |
---|
216 | for ( i; 5~15~2 ) { ... } |
---|
217 | |
---|
218 | for ( i; 10 ) { ... } |
---|
219 | else { ... } // i == 10 |
---|
220 | \end{cfa} |
---|
221 | \end{tabular} |
---|
222 | \end{cquote} |
---|
223 | |
---|
224 | |
---|
225 | \section{Exceptions} |
---|
226 | |
---|
227 | Currently, \CFA uses macros @ExceptionDecl@ and @ExceptionInst@ to declare and instantiate an exception. |
---|
228 | \begin{cquote} |
---|
229 | \begin{tabular}{l|ll} |
---|
230 | \begin{uC++} |
---|
231 | |
---|
232 | struct E { // local or global scope |
---|
233 | ... // exception fields |
---|
234 | }; |
---|
235 | try { |
---|
236 | ... |
---|
237 | if ( ... ) _Resume E( /* initialization */ ); |
---|
238 | if ( ... ) _Throw E( /* initialization */ ); |
---|
239 | ... |
---|
240 | } _CatchResume( E & ) { // should be reference |
---|
241 | ... |
---|
242 | } catch( E & ) { |
---|
243 | ... |
---|
244 | } |
---|
245 | \end{uC++} |
---|
246 | & |
---|
247 | \begin{cfa} |
---|
248 | #include <Exception.hfa> |
---|
249 | @ExceptionDecl@( E, // must be global scope |
---|
250 | ... // exception fields |
---|
251 | ); |
---|
252 | try { |
---|
253 | ... |
---|
254 | if ( ... ) throwResume @ExceptionInst@( E, /* intialization */ ); |
---|
255 | if ( ... ) throw @ExceptionInst@( E, /* intialization */ ); |
---|
256 | ... |
---|
257 | } catchResume( E * ) { // must be pointer |
---|
258 | ... |
---|
259 | } catch( E * ) { |
---|
260 | ... |
---|
261 | } |
---|
262 | \end{cfa} |
---|
263 | \end{tabular} |
---|
264 | \end{cquote} |
---|
265 | |
---|
266 | |
---|
267 | \section{Stream I/O} |
---|
268 | |
---|
269 | \CFA output streams automatically separate values and insert a newline at the end of the print. |
---|
270 | |
---|
271 | \begin{cquote} |
---|
272 | \begin{tabular}{l|l} |
---|
273 | \begin{uC++} |
---|
274 | #include <@iostream@> |
---|
275 | using namespace std; |
---|
276 | int i; double d; char c; |
---|
277 | cin >> i >> d >> c; |
---|
278 | cout << i << ' ' << d << ' ' << c | endl; |
---|
279 | \end{uC++} |
---|
280 | & |
---|
281 | \begin{cfa} |
---|
282 | #include <@fstream.hfa@> |
---|
283 | |
---|
284 | int i; double d; char c; |
---|
285 | sin | i | d | c; |
---|
286 | sout | i | d | c |
---|
287 | \end{cfa} |
---|
288 | \end{tabular} |
---|
289 | \end{cquote} |
---|
290 | |
---|
291 | |
---|
292 | \section{String} |
---|
293 | |
---|
294 | \begin{cquote} |
---|
295 | \begin{tabular}{l|l} |
---|
296 | \multicolumn{2}{l}{\lstinline{string s1, s2;}} \\ |
---|
297 | \begin{uC++} |
---|
298 | s1 = "hi"; |
---|
299 | s2 = s1; |
---|
300 | s1 += s2; |
---|
301 | s1 == s2; s1 != s2; |
---|
302 | s1 < s2; s1 <= s2; s1 > s2; s1 >= s2; |
---|
303 | s1.length(); |
---|
304 | s1[3]; |
---|
305 | s1.substr( 2 ); s1.substr( 2, 3 ); |
---|
306 | s1.replace( 2, 5, s2 ); |
---|
307 | s1.find( s2 ), s1.rfind( s2 ); |
---|
308 | s1.find_first_of( s2 ); s1.find_last_of( s2 ); |
---|
309 | s1.find_first_not_of(s2 ); s1.find_last_not_of( s2 ); |
---|
310 | getline( cin, s1 ); |
---|
311 | cout << s1 << endl; |
---|
312 | \end{uC++} |
---|
313 | & |
---|
314 | \begin{cfa} |
---|
315 | s1 = "hi"; |
---|
316 | s2 = s1; |
---|
317 | s1 += s2; |
---|
318 | s1 == s2; s1 != s2; |
---|
319 | s1 < s2; s1 <= s2; s1 > s2; s1 >= s2; |
---|
320 | size( s1 ); |
---|
321 | s1[3]; |
---|
322 | s1( 2 ); s1( 2, 3 ); |
---|
323 | //s1.replace( 2, 5, s2 ); |
---|
324 | find( s1, s2 ), rfind( s1, s2 ); |
---|
325 | find_first_of( .substr, s2 ); s1.find_last_of( s2 ); |
---|
326 | s1.find_first_not_of(s2 ); s1.find_last_not_of( s2 ); |
---|
327 | sin | getline( s1 ); |
---|
328 | sout | s1; |
---|
329 | \end{cfa} |
---|
330 | \end{tabular} |
---|
331 | \end{cquote} |
---|
332 | |
---|
333 | |
---|
334 | \section{Constructor / Destructor} |
---|
335 | |
---|
336 | \begin{cquote} |
---|
337 | \begin{tabular}{l|l} |
---|
338 | \begin{uC++} |
---|
339 | struct S { |
---|
340 | ... // fields |
---|
341 | @S@(...) { ... } |
---|
342 | @~S@(...) { ... } |
---|
343 | }; |
---|
344 | \end{uC++} |
---|
345 | & |
---|
346 | \begin{cfa} |
---|
347 | struct S { |
---|
348 | ... // fields |
---|
349 | }; |
---|
350 | @?{}@( @S & s,@ ...) { ... } |
---|
351 | @^?{}@( @S & s@ ) { ... } |
---|
352 | \end{cfa} |
---|
353 | \end{tabular} |
---|
354 | \end{cquote} |
---|
355 | |
---|
356 | |
---|
357 | \section{\texorpdfstring{Structures (object-oriented \protect\vs routine style)}{Structures (object-oriented vs. routine style)}} |
---|
358 | |
---|
359 | \begin{cquote} |
---|
360 | \begin{tabular}{l|l} |
---|
361 | \begin{uC++} |
---|
362 | struct S { |
---|
363 | int i = 0; |
---|
364 | int setter( int j ) { int t = i; i = j; return t; } |
---|
365 | int getter() { return i; } |
---|
366 | }; |
---|
367 | |
---|
368 | S s; |
---|
369 | @s.@setter( 3 ); // object-oriented call |
---|
370 | int k = @s.@getter(); |
---|
371 | \end{uC++} |
---|
372 | & |
---|
373 | \begin{cfa} |
---|
374 | struct S { |
---|
375 | int i; |
---|
376 | }; |
---|
377 | void ?{}( S & s ) { s.i = 0; } |
---|
378 | int setter( @S & s,@ int j ) @with(s)@ { int t = i; i = j; return t; } |
---|
379 | int getter( @S & s@ ) @with(s)@ { return i; } |
---|
380 | S s; |
---|
381 | setter( @s,@ 3 ); // normal routine call |
---|
382 | int k = getter( @s@ ); |
---|
383 | \end{cfa} |
---|
384 | \end{tabular} |
---|
385 | \end{cquote} |
---|
386 | |
---|
387 | |
---|
388 | \section{\texorpdfstring{\lstinline{uNoCtor}}{uNoCtor}} |
---|
389 | |
---|
390 | \begin{cquote} |
---|
391 | \begin{tabular}{l|l} |
---|
392 | \begin{uC++} |
---|
393 | struct S { |
---|
394 | int i; |
---|
395 | S( int i ) { S::i = i; cout << S::i << endl; } |
---|
396 | }; |
---|
397 | @uNoCtor<S>@ s[10]; |
---|
398 | int main() { |
---|
399 | for ( int i = 0; i < 10; i += 1 ) { |
---|
400 | s[i].ctor( i ); |
---|
401 | } |
---|
402 | for ( int i = 0; i < 10; i += 1 ) { |
---|
403 | cout << s[i]@->@i << endl; |
---|
404 | } |
---|
405 | } |
---|
406 | \end{uC++} |
---|
407 | & |
---|
408 | \begin{cfa} |
---|
409 | struct S { |
---|
410 | int i; |
---|
411 | }; |
---|
412 | void ?{}( S & s, int i ) { s.i = i; sout | s.i; } |
---|
413 | S s[10] @$\color{red}@$= {}@; |
---|
414 | int main() { |
---|
415 | for ( i; 10 ) { |
---|
416 | ?{}( s[i], i ); // call constructor |
---|
417 | } |
---|
418 | for ( i; 10 ) { |
---|
419 | sout | s[i]@.@i; // dot not arrow |
---|
420 | } |
---|
421 | } |
---|
422 | \end{cfa} |
---|
423 | \end{tabular} |
---|
424 | \end{cquote} |
---|
425 | |
---|
426 | |
---|
427 | \section{Coroutines} |
---|
428 | |
---|
429 | \begin{cquote} |
---|
430 | \begin{tabular}{l|ll} |
---|
431 | \begin{uC++} |
---|
432 | |
---|
433 | _Coroutine C { |
---|
434 | // private coroutine fields |
---|
435 | void main() { |
---|
436 | ... suspend(); ... |
---|
437 | ... _Resume E( ... ) _At partner; |
---|
438 | } |
---|
439 | public: |
---|
440 | void mem( ... ) { |
---|
441 | ... resume() ... |
---|
442 | } |
---|
443 | }; |
---|
444 | \end{uC++} |
---|
445 | & |
---|
446 | \begin{cfa} |
---|
447 | #include <$coroutine$.hfa> |
---|
448 | coroutine C { |
---|
449 | // private coroutine fields |
---|
450 | |
---|
451 | }; |
---|
452 | void main( C & c ) { |
---|
453 | ... suspend; ... // keyword not routine |
---|
454 | ... resumeAt( partner, ExceptionInst( E, ... ) ); |
---|
455 | } |
---|
456 | void mem( C & c, ... ) { |
---|
457 | ... resume(); ... |
---|
458 | } |
---|
459 | \end{cfa} |
---|
460 | \\ |
---|
461 | \multicolumn{2}{l}{\lstinline{C c;}} |
---|
462 | \end{tabular} |
---|
463 | \end{cquote} |
---|
464 | |
---|
465 | |
---|
466 | \section{Locks} |
---|
467 | |
---|
468 | \begin{cquote} |
---|
469 | \begin{tabular}{l|ll} |
---|
470 | \begin{uC++} |
---|
471 | |
---|
472 | uOwnerLock m; |
---|
473 | uCondLock s; |
---|
474 | bool avail = true; |
---|
475 | m.acquire(); |
---|
476 | if ( ! avail ) s.wait( m ); |
---|
477 | else { |
---|
478 | avail = false; |
---|
479 | m.release(); |
---|
480 | } |
---|
481 | @osacquire( cout )@ << i << endl; |
---|
482 | \end{uC++} |
---|
483 | & |
---|
484 | \begin{cfa} |
---|
485 | #include <locks.hfa> |
---|
486 | owner_lock m; |
---|
487 | condition_variable( owner_lock ) s; |
---|
488 | bool avail = true; |
---|
489 | lock( m ); |
---|
490 | if ( ! avail ) wait( s, m ); |
---|
491 | else { |
---|
492 | avail = false; |
---|
493 | unlock( m ); |
---|
494 | } |
---|
495 | @mutex( sout )@ sout | i; // safe I/O |
---|
496 | \end{cfa} |
---|
497 | \end{tabular} |
---|
498 | \end{cquote} |
---|
499 | |
---|
500 | |
---|
501 | \section{Monitors} |
---|
502 | |
---|
503 | \begin{cquote} |
---|
504 | \begin{tabular}{l|ll} |
---|
505 | \begin{uC++} |
---|
506 | |
---|
507 | @_Monitor@ M { |
---|
508 | @uCondition@ c; |
---|
509 | bool avail = true; |
---|
510 | public: |
---|
511 | |
---|
512 | void rtn() { |
---|
513 | if ( ! avail ) c.wait(); |
---|
514 | else avail = false; |
---|
515 | } |
---|
516 | }; |
---|
517 | \end{uC++} |
---|
518 | & |
---|
519 | \begin{cfa} |
---|
520 | #include <$monitor$.hfa> |
---|
521 | @monitor@ M { |
---|
522 | @condition@ c; |
---|
523 | bool avail; |
---|
524 | }; |
---|
525 | void ?{}( M & m ) { m.avail = true; } |
---|
526 | void rtn( M & m ) with( m ) { |
---|
527 | if ( ! avail ) wait( c ); |
---|
528 | else avail = false; |
---|
529 | } |
---|
530 | |
---|
531 | \end{cfa} |
---|
532 | \\ |
---|
533 | \multicolumn{2}{l}{\lstinline{M m;}} |
---|
534 | \end{tabular} |
---|
535 | \end{cquote} |
---|
536 | |
---|
537 | |
---|
538 | \section{Threads} |
---|
539 | |
---|
540 | \begin{cquote} |
---|
541 | \begin{tabular}{l|ll} |
---|
542 | \begin{uC++} |
---|
543 | |
---|
544 | @_Task@ T { |
---|
545 | // private task fields |
---|
546 | void main() { |
---|
547 | ... _Resume E( ... ) _At partner; |
---|
548 | } |
---|
549 | public: |
---|
550 | }; |
---|
551 | \end{uC++} |
---|
552 | & |
---|
553 | \begin{cfa} |
---|
554 | #include <$thread$.hfa> |
---|
555 | @thread@ T { |
---|
556 | // private task fields |
---|
557 | |
---|
558 | }; |
---|
559 | void main( @T & t@ ) { |
---|
560 | ... resumeAt( partner, ExceptionInst( E, ... ) ); |
---|
561 | } |
---|
562 | \end{cfa} |
---|
563 | \\ |
---|
564 | \multicolumn{2}{l}{\lstinline{T t; // start thread in main routine}} |
---|
565 | \end{tabular} |
---|
566 | \end{cquote} |
---|
567 | |
---|
568 | |
---|
569 | \input{uC++toCFA.ind} |
---|
570 | |
---|
571 | % \bibliographystyle{plain} |
---|
572 | % \bibliography{pl} |
---|
573 | |
---|
574 | \end{document} |
---|
575 | |
---|
576 | % Local Variables: % |
---|
577 | % tab-width: 4 % |
---|
578 | % fill-column: 100 % |
---|
579 | % compile-command: "make" % |
---|
580 | % End: % |
---|