Changes in doc/user/user.tex [816d61c:46e4440e]
- File:
-
- 1 edited
-
doc/user/user.tex (modified) (37 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
r816d61c r46e4440e 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Fri Jun 16 12:00:01201714 %% Update Count : 24 3313 %% Last Modified On : Tue Jun 13 11:50:27 2017 14 %% Update Count : 2403 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 43 43 \usepackage[pagewise]{lineno} 44 44 \renewcommand{\linenumberfont}{\scriptsize\sffamily} 45 \input{common} % common CFA document macros45 \input{common} % bespoke macros used in the document 46 46 \usepackage[dvips,plainpages=false,pdfpagelabels,pdfpagemode=UseNone,colorlinks=true,pagebackref=true,linkcolor=blue,citecolor=blue,urlcolor=blue,pagebackref=true,breaklinks=true]{hyperref} 47 47 \usepackage{breakurl} … … 110 110 \renewcommand{\subsectionmark}[1]{\markboth{\thesubsection\quad #1}{\thesubsection\quad #1}} 111 111 \pagenumbering{roman} 112 %\linenumbers % comment out to turn off line numbering112 \linenumbers % comment out to turn off line numbering 113 113 114 114 \maketitle … … 881 881 882 882 883 \subsection{Address-of Semantics} 884 885 In C, ©&E© is an rvalue for any expression ©E©. 886 \CFA extends the ©&© (address-of) operator as follows: 887 \begin{itemize} 888 \item 889 if ©R© is an \Index{rvalue} of type ©T &$_1$...&$_r$© where $r \ge 1$ references (©&© symbols) than ©&R© has type ©T ®*®&$_{\color{red}2}$...&$_{\color{red}r}$©, \ie ©T© pointer with $r-1$ references (©&© symbols). 890 891 \item 892 if ©L© is an \Index{lvalue} of type ©T &$_1$...&$_l$© where $l \ge 0$ references (©&© symbols) then ©&L© has type ©T ®*®&$_{\color{red}1}$...&$_{\color{red}l}$©, \ie ©T© pointer with $l$ references (©&© symbols). 893 \end{itemize} 894 The following example shows the first rule applied to different \Index{rvalue} contexts: 895 \begin{cfa} 896 int x, * px, ** ppx, *** pppx, **** ppppx; 897 int & rx = x, && rrx = rx, &&& rrrx = rrx ; 898 x = rrrx; // rrrx is an lvalue with type int &&& (equivalent to x) 899 px = &rrrx; // starting from rrrx, &rrrx is an rvalue with type int *&&& (&x) 900 ppx = &&rrrx; // starting from &rrrx, &&rrrx is an rvalue with type int **&& (&rx) 901 pppx = &&&rrrx; // starting from &&rrrx, &&&rrrx is an rvalue with type int ***& (&rrx) 902 ppppx = &&&&rrrx; // starting from &&&rrrx, &&&&rrrx is an rvalue with type int **** (&rrrx) 903 \end{cfa} 904 The following example shows the second rule applied to different \Index{lvalue} contexts: 905 \begin{cfa} 906 int x, * px, ** ppx, *** pppx; 907 int & rx = x, && rrx = rx, &&& rrrx = rrx ; 908 rrrx = 2; // rrrx is an lvalue with type int &&& (equivalent to x) 909 &rrrx = px; // starting from rrrx, &rrrx is an rvalue with type int *&&& (rx) 910 &&rrrx = ppx; // starting from &rrrx, &&rrrx is an rvalue with type int **&& (rrx) 911 &&&rrrx = pppx; // starting from &&rrrx, &&&rrrx is an rvalue with type int ***& (rrrx) 912 \end{cfa} 913 914 915 \subsection{Conversions} 916 917 C provides a basic implicit conversion to simplify variable usage: 918 \begin{enumerate} 919 \setcounter{enumi}{-1} 920 \item 921 lvalue to rvalue conversion: ©cv T© converts to ©T©, which allows implicit variable dereferencing. 922 \begin{cfa} 923 int x; 924 x + 1; // lvalue variable (int) converts to rvalue for expression 925 \end{cfa} 926 An rvalue has no type qualifiers (©cv©), so the lvalue qualifiers are dropped. 927 \end{enumerate} 928 \CFA provides three new implicit conversion for reference types to simplify reference usage. 929 \begin{enumerate} 930 \item 931 reference to rvalue conversion: ©cv T &© converts to ©T©, which allows implicit reference dereferencing. 932 \begin{cfa} 933 int x, &r = x, f( int p ); 934 x = ®r® + f( ®r® ); // lvalue reference converts to rvalue 935 \end{cfa} 936 An rvalue has no type qualifiers (©cv©), so the reference qualifiers are dropped. 937 938 \item 939 lvalue to reference conversion: \lstinline[deletekeywords={lvalue}]@lvalue-type cv1 T@ converts to ©cv2 T &©, which allows implicitly converting variables to references. 940 \begin{cfa} 941 int x, &r = ®x®, f( int & p ); // lvalue variable (int) convert to reference (int &) 942 f( ®x® ); // lvalue variable (int) convert to reference (int &) 943 \end{cfa} 944 Conversion can restrict a type, where ©cv1© $\le$ ©cv2©, \eg passing an ©int© to a ©const volatile int &©, which has low cost. 945 Conversion can expand a type, where ©cv1© $>$ ©cv2©, \eg passing a ©const volatile int© to an ©int &©, which has high cost (\Index{warning}); 946 furthermore, if ©cv1© has ©const© but not ©cv2©, a temporary variable is created to preserve the immutable lvalue. 947 948 \item 949 rvalue to reference conversion: ©T© converts to ©cv T &©, which allows binding references to temporaries. 950 \begin{cfa} 951 int x, & f( int & p ); 952 f( ®x + 3® ); // rvalue parameter (int) implicitly converts to lvalue temporary reference (int &) 953 ®&f®(...) = &x; // rvalue result (int &) implicitly converts to lvalue temporary reference (int &) 954 \end{cfa} 955 In both case, modifications to the temporary are inaccessible (\Index{warning}). 956 Conversion expands the temporary-type with ©cv©, which is low cost since the temporary is inaccessible. 957 \end{enumerate} 958 959 883 960 \subsection{Initialization} 884 961 … … 961 1038 962 1039 963 \subsection{Address-of Semantics}964 965 In C, ©&E© is an rvalue for any expression ©E©.966 \CFA extends the ©&© (address-of) operator as follows:967 \begin{itemize}968 \item969 if ©R© is an \Index{rvalue} of type ©T &$_1$...&$_r$© where $r \ge 1$ references (©&© symbols) than ©&R© has type ©T ®*®&$_{\color{red}2}$...&$_{\color{red}r}$©, \ie ©T© pointer with $r-1$ references (©&© symbols).970 971 \item972 if ©L© is an \Index{lvalue} of type ©T &$_1$...&$_l$© where $l \ge 0$ references (©&© symbols) then ©&L© has type ©T ®*®&$_{\color{red}1}$...&$_{\color{red}l}$©, \ie ©T© pointer with $l$ references (©&© symbols).973 \end{itemize}974 The following example shows the first rule applied to different \Index{rvalue} contexts:975 \begin{cfa}976 int x, * px, ** ppx, *** pppx, **** ppppx;977 int & rx = x, && rrx = rx, &&& rrrx = rrx ;978 x = rrrx; // rrrx is an lvalue with type int &&& (equivalent to x)979 px = &rrrx; // starting from rrrx, &rrrx is an rvalue with type int *&&& (&x)980 ppx = &&rrrx; // starting from &rrrx, &&rrrx is an rvalue with type int **&& (&rx)981 pppx = &&&rrrx; // starting from &&rrrx, &&&rrrx is an rvalue with type int ***& (&rrx)982 ppppx = &&&&rrrx; // starting from &&&rrrx, &&&&rrrx is an rvalue with type int **** (&rrrx)983 \end{cfa}984 The following example shows the second rule applied to different \Index{lvalue} contexts:985 \begin{cfa}986 int x, * px, ** ppx, *** pppx;987 int & rx = x, && rrx = rx, &&& rrrx = rrx ;988 rrrx = 2; // rrrx is an lvalue with type int &&& (equivalent to x)989 &rrrx = px; // starting from rrrx, &rrrx is an rvalue with type int *&&& (rx)990 &&rrrx = ppx; // starting from &rrrx, &&rrrx is an rvalue with type int **&& (rrx)991 &&&rrrx = pppx; // starting from &&rrrx, &&&rrrx is an rvalue with type int ***& (rrrx)992 \end{cfa}993 994 995 \subsection{Conversions}996 997 C provides a basic implicit conversion to simplify variable usage:998 \begin{enumerate}999 \setcounter{enumi}{-1}1000 \item1001 lvalue to rvalue conversion: ©cv T© converts to ©T©, which allows implicit variable dereferencing.1002 \begin{cfa}1003 int x;1004 x + 1; // lvalue variable (int) converts to rvalue for expression1005 \end{cfa}1006 An rvalue has no type qualifiers (©cv©), so the lvalue qualifiers are dropped.1007 \end{enumerate}1008 \CFA provides three new implicit conversion for reference types to simplify reference usage.1009 \begin{enumerate}1010 \item1011 reference to rvalue conversion: ©cv T &© converts to ©T©, which allows implicit reference dereferencing.1012 \begin{cfa}1013 int x, &r = x, f( int p );1014 x = ®r® + f( ®r® ); // lvalue reference converts to rvalue1015 \end{cfa}1016 An rvalue has no type qualifiers (©cv©), so the reference qualifiers are dropped.1017 1018 \item1019 lvalue to reference conversion: \lstinline[deletekeywords={lvalue}]@lvalue-type cv1 T@ converts to ©cv2 T &©, which allows implicitly converting variables to references.1020 \begin{cfa}1021 int x, &r = ®x®, f( int & p ); // lvalue variable (int) convert to reference (int &)1022 f( ®x® ); // lvalue variable (int) convert to reference (int &)1023 \end{cfa}1024 Conversion can restrict a type, where ©cv1© $\le$ ©cv2©, \eg passing an ©int© to a ©const volatile int &©, which has low cost.1025 Conversion can expand a type, where ©cv1© $>$ ©cv2©, \eg passing a ©const volatile int© to an ©int &©, which has high cost (\Index{warning});1026 furthermore, if ©cv1© has ©const© but not ©cv2©, a temporary variable is created to preserve the immutable lvalue.1027 1028 \item1029 rvalue to reference conversion: ©T© converts to ©cv T &©, which allows binding references to temporaries.1030 \begin{cfa}1031 int x, & f( int & p );1032 f( ®x + 3® ); // rvalue parameter (int) implicitly converts to lvalue temporary reference (int &)1033 ®&f®(...) = &x; // rvalue result (int &) implicitly converts to lvalue temporary reference (int &)1034 \end{cfa}1035 In both case, modifications to the temporary are inaccessible (\Index{warning}).1036 Conversion expands the temporary-type with ©cv©, which is low cost since the temporary is inaccessible.1037 \end{enumerate}1038 1039 1040 1040 1041 \begin{comment} 1042 \section{References} 1043 1044 By introducing references in parameter types, users are given an easy way to pass a value by reference, without the need for NULL pointer checks. 1045 In structures, a reference can replace a pointer to an object that should always have a valid value. 1046 When a structure contains a reference, all of its constructors must initialize the reference and all instances of this structure must initialize it upon definition. 1047 1048 The syntax for using references in \CFA is the same as \CC with the exception of reference initialization. 1049 Use ©&© to specify a reference, and access references just like regular objects, not like pointers (use dot notation to access fields). 1050 When initializing a reference, \CFA uses a different syntax which differentiates reference initialization from assignment to a reference. 1051 The ©&© is used on both sides of the expression to clarify that the address of the reference is being set to the address of the variable to which it refers. 1052 1053 1041 1054 From: Richard Bilson <rcbilson@gmail.com> 1042 1055 Date: Wed, 13 Jul 2016 01:58:58 +0000 … … 1200 1213 \section{Routine Definition} 1201 1214 1202 \CFA also supports a new syntax for routine definition, as well as \Celevenand K\&R routine syntax.1215 \CFA also supports a new syntax for routine definition, as well as ISO C and K\&R routine syntax. 1203 1216 The point of the new syntax is to allow returning multiple values from a routine~\cite{Galletly96,CLU}, \eg: 1204 1217 \begin{cfa} … … 1220 1233 in both cases the type is assumed to be void as opposed to old style C defaults of int return type and unknown parameter types, respectively, as in: 1221 1234 \begin{cfa} 1222 [§\,§] g(); §\C{// no input or output parameters}§1223 [ void ] g( void ); §\C{// no input or output parameters}§1235 [§\,§] g(); §\C{// no input or output parameters}§ 1236 [ void ] g( void ); §\C{// no input or output parameters}§ 1224 1237 \end{cfa} 1225 1238 … … 1239 1252 \begin{cfa} 1240 1253 typedef int foo; 1241 int f( int (* foo) ); §\C{// foo is redefined as a parameter name}§1254 int f( int (* foo) ); §\C{// foo is redefined as a parameter name}§ 1242 1255 \end{cfa} 1243 1256 The string ``©int (* foo)©'' declares a C-style named-parameter of type pointer to an integer (the parenthesis are superfluous), while the same string declares a \CFA style unnamed parameter of type routine returning integer with unnamed parameter of type pointer to foo. … … 1247 1260 C-style declarations can be used to declare parameters for \CFA style routine definitions, \eg: 1248 1261 \begin{cfa} 1249 [ int ] f( * int, int * ); §\C{// returns an integer, accepts 2 pointers to integers}§1250 [ * int, int * ] f( int ); §\C{// returns 2 pointers to integers, accepts an integer}§1262 [ int ] f( * int, int * ); §\C{// returns an integer, accepts 2 pointers to integers}§ 1263 [ * int, int * ] f( int ); §\C{// returns 2 pointers to integers, accepts an integer}§ 1251 1264 \end{cfa} 1252 1265 The reason for allowing both declaration styles in the new context is for backwards compatibility with existing preprocessor macros that generate C-style declaration-syntax, as in: 1253 1266 \begin{cfa} 1254 1267 #define ptoa( n, d ) int (*n)[ d ] 1255 int f( ptoa( p, 5 ) ) ... §\C{// expands to int f( int (*p)[ 5 ] )}§1256 [ int ] f( ptoa( p, 5 ) ) ... §\C{// expands to [ int ] f( int (*p)[ 5 ] )}§1268 int f( ptoa( p, 5 ) ) ... §\C{// expands to int f( int (*p)[ 5 ] )}§ 1269 [ int ] f( ptoa( p, 5 ) ) ... §\C{// expands to [ int ] f( int (*p)[ 5 ] )}§ 1257 1270 \end{cfa} 1258 1271 Again, programmers are highly encouraged to use one declaration form or the other, rather than mixing the forms. … … 1276 1289 int z; 1277 1290 ... x = 0; ... y = z; ... 1278 ®return;® §\C{// implicitly return x, y}§1291 ®return;® §\C{// implicitly return x, y}§ 1279 1292 } 1280 1293 \end{cfa} … … 1286 1299 [ int x, int y ] f() { 1287 1300 ... 1288 } §\C{// implicitly return x, y}§1301 } §\C{// implicitly return x, y}§ 1289 1302 \end{cfa} 1290 1303 In this case, the current values of ©x© and ©y© are returned to the calling routine just as if a ©return© had been encountered. 1291 1292 Named return values may be used in conjunction with named parameter values;1293 specifically, a return and parameter can have the same name.1294 \begin{cfa}1295 [ int x, int y ] f( int, x, int y ) {1296 ...1297 } §\C{// implicitly return x, y}§1298 \end{cfa}1299 This notation allows the compiler to eliminate temporary variables in nested routine calls.1300 \begin{cfa}1301 [ int x, int y ] f( int, x, int y ); §\C{// prototype declaration}§1302 int a, b;1303 [a, b] = f( f( f( a, b ) ) );1304 \end{cfa}1305 While the compiler normally ignores parameters names in prototype declarations, here they are used to eliminate temporary return-values by inferring that the results of each call are the inputs of the next call, and ultimately, the left-hand side of the assignment.1306 Hence, even without the body of routine ©f© (separate compilation), it is possible to perform a global optimization across routine calls.1307 The compiler warns about naming inconsistencies between routine prototype and definition in this case, and behaviour is \Index{undefined} if the programmer is inconsistent.1308 1304 1309 1305 … … 1313 1309 as well, parameter names are optional, \eg: 1314 1310 \begin{cfa} 1315 [ int x ] f (); §\C{// returning int with no parameters}§1316 [ * int ] g (int y); §\C{// returning pointer to int with int parameter}§1317 [ ] h ( int, char );§\C{// returning no result with int and char parameters}§1318 [ * int, int ] j ( int );§\C{// returning pointer to int and int, with int parameter}§1311 [ int x ] f (); §\C{// returning int with no parameters}§ 1312 [ * int ] g (int y); §\C{// returning pointer to int with int parameter}§ 1313 [ ] h (int,char); §\C{// returning no result with int and char parameters}§ 1314 [ * int,int ] j (int); §\C{// returning pointer to int and int, with int parameter}§ 1319 1315 \end{cfa} 1320 1316 This syntax allows a prototype declaration to be created by cutting and pasting source text from the routine definition header (or vice versa). … … 1324 1320 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{C}} \\ 1325 1321 \begin{cfa} 1326 [ int ] f( int), g;1322 [ int ] f(int), g; 1327 1323 \end{cfa} 1328 1324 & 1329 1325 \begin{cfa} 1330 int f( int ), g( int);1326 int f(int), g(int); 1331 1327 \end{cfa} 1332 1328 \end{tabular} … … 1334 1330 Declaration qualifiers can only appear at the start of a \CFA routine declaration,\footref{StorageClassSpecifier} \eg: 1335 1331 \begin{cfa} 1336 extern [ int ] f ( int);1337 static [ int ] g ( int);1332 extern [ int ] f (int); 1333 static [ int ] g (int); 1338 1334 \end{cfa} 1339 1335 … … 1343 1339 The syntax for pointers to \CFA routines specifies the pointer name on the right, \eg: 1344 1340 \begin{cfa} 1345 * [ int x ] () fp; §\C{// pointer to routine returning int with no parameters}§1346 * [ * int ] (int y) gp; §\C{// pointer to routine returning pointer to int with int parameter}§1347 * [ ] (int,char) hp; §\C{// pointer to routine returning no result with int and char parameters}§1348 * [ * int,int ] ( int ) jp;§\C{// pointer to routine returning pointer to int and int, with int parameter}§1341 * [ int x ] () fp; §\C{// pointer to routine returning int with no parameters}§ 1342 * [ * int ] (int y) gp; §\C{// pointer to routine returning pointer to int with int parameter}§ 1343 * [ ] (int,char) hp; §\C{// pointer to routine returning no result with int and char parameters}§ 1344 * [ * int,int ] (int) jp; §\C{// pointer to routine returning pointer to int and int, with int parameter}§ 1349 1345 \end{cfa} 1350 1346 While parameter names are optional, \emph{a routine name cannot be specified}; 1351 1347 for example, the following is incorrect: 1352 1348 \begin{cfa} 1353 * [ int x ] f () fp; §\C{// routine name "f" is not allowed}§1349 * [ int x ] f () fp; §\C{// routine name "f" is not allowed}§ 1354 1350 \end{cfa} 1355 1351 … … 1538 1534 int ; §\C{// disallowed, unnamed field}§ 1539 1535 int *; §\C{// disallowed, unnamed field}§ 1540 int (*)( int); §\C{// disallowed, unnamed field}§1536 int (*)(int); §\C{// disallowed, unnamed field}§ 1541 1537 }; 1542 1538 \end{cfa} … … 1661 1657 } 1662 1658 int main() { 1663 * [int]( int ) fp = foo(); §\C{// int (*fp)( int)}§1659 * [int](int) fp = foo(); §\C{// int (*fp)(int)}§ 1664 1660 sout | fp( 3 ) | endl; 1665 1661 } … … 2782 2778 2783 2779 2784 \s ection{Constructors and Destructors}2780 \subsection{Constructors and Destructors} 2785 2781 2786 2782 \CFA supports C initialization of structures, but it also adds constructors for more advanced initialization. … … 3113 3109 3114 3110 3115 \begin{comment}3116 3111 \section{Generics} 3117 3112 … … 3320 3315 } 3321 3316 \end{cfa} 3322 \end{comment}3323 3317 3324 3318 … … 3380 3374 Complex *p3 = new(0.5, 1.0); // allocate + 2 param constructor 3381 3375 } 3376 3382 3377 \end{cfa} 3383 3378 … … 3391 3386 3392 3387 3393 \begin{comment}3394 3388 \subsection{Unsafe C Constructs} 3395 3389 … … 3402 3396 The exact set of unsafe C constructs that will be disallowed in \CFA has not yet been decided, but is sure to include pointer arithmetic, pointer casting, etc. 3403 3397 Once the full set is decided, the rules will be listed here. 3404 \end{comment}3405 3398 3406 3399 3407 3400 \section{Concurrency} 3401 3402 Today's processors for nearly all use cases, ranging from embedded systems to large cloud computing servers, are composed of multiple cores, often heterogeneous. 3403 As machines grow in complexity, it becomes more difficult for a program to make the most use of the hardware available. 3404 \CFA includes built-in concurrency features to enable high performance and improve programmer productivity on these multi-/many-core machines. 3408 3405 3409 3406 Concurrency support in \CFA is implemented on top of a highly efficient runtime system of light-weight, M:N, user level threads. … … 3412 3409 This enables a very familiar interface to all programmers, even those with no parallel programming experience. 3413 3410 It also allows the compiler to do static type checking of all communication, a very important safety feature. 3414 This controlled communication with type safety has some similarities with channels in \Index*{Go}, and can actually implement channels exactly, as well as create additional communication patterns that channels cannot. 3411 This controlled communication with type safety has some similarities with channels in \Index*{Go}, and can actually implement 3412 channels exactly, as well as create additional communication patterns that channels cannot. 3415 3413 Mutex objects, monitors, are used to contain mutual exclusion within an object and synchronization across concurrent threads. 3416 3414 3417 \begin{figure} 3418 \begin{cfa} 3419 #include <fstream> 3420 #include <coroutine> 3421 3422 coroutine Fibonacci { 3423 int fn; §\C{// used for communication}§ 3424 }; 3425 void ?{}( Fibonacci * this ) { 3426 this->fn = 0; 3427 } 3428 void main( Fibonacci * this ) { 3429 int fn1, fn2; §\C{// retained between resumes}§ 3430 this->fn = 0; §\C{// case 0}§ 3431 fn1 = this->fn; 3432 suspend(); §\C{// return to last resume}§ 3433 3434 this->fn = 1; §\C{// case 1}§ 3435 fn2 = fn1; 3436 fn1 = this->fn; 3437 suspend(); §\C{// return to last resume}§ 3438 3439 for ( ;; ) { §\C{// general case}§ 3440 this->fn = fn1 + fn2; 3441 fn2 = fn1; 3442 fn1 = this->fn; 3443 suspend(); §\C{// return to last resume}§ 3444 } // for 3445 } 3446 int next( Fibonacci * this ) { 3447 resume( this ); §\C{// transfer to last suspend}§ 3448 return this->fn; 3449 } 3450 int main() { 3451 Fibonacci f1, f2; 3452 for ( int i = 1; i <= 10; i += 1 ) { 3453 sout | next( &f1 ) | ' ' | next( &f2 ) | endl; 3454 } // for 3455 } 3456 \end{cfa} 3457 \caption{Fibonacci Coroutine} 3458 \label{f:FibonacciCoroutine} 3459 \end{figure} 3460 3461 3462 \subsection{Coroutine} 3463 3464 \Index{Coroutines} are the precursor to tasks. 3465 \VRef[Figure]{f:FibonacciCoroutine} shows a coroutine that computes the \Index*{Fibonacci} numbers. 3415 Three new keywords are added to support these features: 3416 3417 monitor creates a structure with implicit locking when accessing fields 3418 3419 mutex implies use of a monitor requiring the implicit locking 3420 3421 task creates a type with implicit locking, separate stack, and a thread 3466 3422 3467 3423 … … 3478 3434 \end{cfa} 3479 3435 3480 \begin{figure}3481 \begin{cfa}3482 #include <fstream>3483 #include <kernel>3484 #include <monitor>3485 #include <thread>3486 3487 monitor global_t {3488 int value;3489 };3490 3491 void ?{}(global_t * this) {3492 this->value = 0;3493 }3494 3495 static global_t global;3496 3497 void increment3( global_t * mutex this ) {3498 this->value += 1;3499 }3500 void increment2( global_t * mutex this ) {3501 increment3( this );3502 }3503 void increment( global_t * mutex this ) {3504 increment2( this );3505 }3506 3507 thread MyThread {};3508 3509 void main( MyThread* this ) {3510 for(int i = 0; i < 1_000_000; i++) {3511 increment( &global );3512 }3513 }3514 int main(int argc, char* argv[]) {3515 processor p;3516 {3517 MyThread f[4];3518 }3519 sout | global.value | endl;3520 }3521 \end{cfa}3522 \caption{Atomic-Counter Monitor}3523 \caption{f:AtomicCounterMonitor}3524 \end{figure}3525 3526 \begin{comment}3527 3436 Since a monitor structure includes an implicit locking mechanism, it does not make sense to copy a monitor; 3528 3437 it is always passed by reference. … … 3571 3480 } 3572 3481 \end{cfa} 3573 \end{comment}3574 3482 3575 3483 … … 3579 3487 A task provides mutual exclusion like a monitor, and also has its own execution state and a thread of control. 3580 3488 Similar to a monitor, a task is defined like a structure: 3581 3582 \begin{figure}3583 \begin{cfa}3584 #include <fstream>3585 #include <kernel>3586 #include <stdlib>3587 #include <thread>3588 3589 thread First { signal_once * lock; };3590 thread Second { signal_once * lock; };3591 3592 void ?{}( First * this, signal_once* lock ) { this->lock = lock; }3593 void ?{}( Second * this, signal_once* lock ) { this->lock = lock; }3594 3595 void main( First * this ) {3596 for ( int i = 0; i < 10; i += 1 ) {3597 sout | "First : Suspend No." | i + 1 | endl;3598 yield();3599 }3600 signal( this->lock );3601 }3602 3603 void main( Second * this ) {3604 wait( this->lock );3605 for ( int i = 0; i < 10; i += 1 ) {3606 sout | "Second : Suspend No." | i + 1 | endl;3607 yield();3608 }3609 }3610 3611 int main( void ) {3612 signal_once lock;3613 sout | "User main begin" | endl;3614 {3615 processor p;3616 {3617 First f = { &lock };3618 Second s = { &lock };3619 }3620 }3621 sout | "User main end" | endl;3622 }3623 \end{cfa}3624 \caption{Simple Tasks}3625 \label{f:SimpleTasks}3626 \end{figure}3627 3628 3629 \begin{comment}3630 3489 \begin{cfa} 3631 3490 type Adder = task { … … 3681 3540 \end{cfa} 3682 3541 3542 3683 3543 \subsection{Cooperative Scheduling} 3684 3544 … … 3793 3653 } 3794 3654 \end{cfa} 3795 \end{comment} 3796 3655 3656 3657 \section{Modules and Packages } 3797 3658 3798 3659 \begin{comment} 3799 \section{Modules and Packages }3800 3801 3660 High-level encapsulation is useful for organizing code into reusable units, and accelerating compilation speed. 3802 3661 \CFA provides a convenient mechanism for creating, building and sharing groups of functionality that enhances productivity and improves compile time. … … 4462 4321 4463 4322 4464 \begin{comment}4465 4323 \subsection[Comparing Key Features of CFA]{Comparing Key Features of \CFA} 4466 4324 … … 4840 4698 4841 4699 4700 \begin{comment} 4842 4701 \subsubsection{Modules / Packages} 4843 4702 … … 4919 4778 } 4920 4779 \end{cfa} 4780 \end{comment} 4921 4781 4922 4782 … … 5079 4939 5080 4940 \subsection{Summary of Language Comparison} 5081 \end{comment} 5082 5083 5084 \subsection[C++]{\CC} 4941 4942 4943 \subsubsection[C++]{\CC} 5085 4944 5086 4945 \Index*[C++]{\CC{}} is a general-purpose programming language. … … 5103 4962 5104 4963 5105 \subs ection{Go}4964 \subsubsection{Go} 5106 4965 5107 4966 \Index*{Go}, also commonly referred to as golang, is a programming language developed at Google in 2007 [.]. … … 5119 4978 5120 4979 5121 \subs ection{Rust}4980 \subsubsection{Rust} 5122 4981 5123 4982 \Index*{Rust} is a general-purpose, multi-paradigm, compiled programming language developed by Mozilla Research. … … 5133 4992 5134 4993 5135 \subs ection{D}4994 \subsubsection{D} 5136 4995 5137 4996 The \Index*{D} programming language is an object-oriented, imperative, multi-paradigm system programming … … 5245 5104 \item[Rationale:] keywords added to implement new semantics of \CFA. 5246 5105 \item[Effect on original feature:] change to semantics of well-defined feature. \\ 5247 Any \Celevenprograms using these keywords as identifiers are invalid \CFA programs.5106 Any ISO C programs using these keywords as identifiers are invalid \CFA programs. 5248 5107 \item[Difficulty of converting:] keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism (see~\VRef{s:BackquoteIdentifiers}). 5249 5108 \item[How widely used:] clashes among new \CFA keywords and existing identifiers are rare.
Note:
See TracChangeset
for help on using the changeset viewer.