Changeset 8659435


Ignore:
Timestamp:
Mar 1, 2026, 5:19:18 PM (12 hours ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
8086004
Parents:
acb89d74
Message:

update choose and waituntil statements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/uC++toCFA/uC++toCFA.tex

    racb89d74 r8659435  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Mon Nov 17 11:14:48 2025
    14 %% Update Count     : 6677
     13%% Last Modified On : Fri Feb 20 11:19:31 2026
     14%% Update Count     : 6717
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    194194
    195195The @choose@ statement provides an implicit @break@ after the @case@ clause for safety.
    196 It is possible to @break default@ in a @case@ clause to transfer to common code in the @default@ clause.
    197 \begin{cquote}
    198 \begin{tabular}{@{}l|l@{}}
    199 \begin{uC++}
     196It is possible to @fallthrough@ label in a @case@ clause to transfer to common code or the @default@ clause.
     197\begin{cquote}
     198\begin{tabular}{@{}l|l@{}}
     199\begin{cfa}
    200200switch ( i ) {
    201   case 1: ... @break@; // explicit break
    202   case 2: ... @break@; // explicit break
     201  case 3: ... @fallthrough common@;
     202  case 2: if ( ... ) @fallthrough@;
     203  case 1:
     204  common: ... ; // implicit fall through
    203205  default: ... ;
    204206}
    205 \end{uC++}
     207\end{cfa}
    206208&
    207209\begin{cfa}
    208210choose ( i ) {
    209   case 1: ... ; // implicit break
    210   case 2: ... ; // implicit break
     211  case 3: ... @fallthrough common@; // labelled explicit fallthrough
     212  case 2: if ( ... ) @fallthrough@; // conditional explicit fallthrough
     213  case 1:
     214  common: ... ; // implicit break
    211215  default: ... ;
    212216}
     
    250254for ( i; @5@ ~ @15@ ~ @2@ ) { ... } // 5 to 14 by 2
    251255for ( i; -2 ~@=@ 10 ~ 3 ) { ... } // -2 to 10 by 3
    252 for ( i; -3 @-@~ 10 ) { ... } // not 10 -~= -3, 10 to -2 by -1
    253 for ( i; 0 @-@~@=@ 10 ) { ... } // not 10 -~= 0, 10 to 0 by -1
     256for ( i; -3 @-@~ 10 ) { ... } // 10 to -2 by -1, not 10 -~= -3
     257for ( i; 0 @-@~@=@ 10 ) { ... } // 10 to 0 by -1, not 10 -~= 0
    254258\end{cfa}
    255259\end{tabular}
     
    908912  public:
    909913};
     914T t;
     915uProcessor p[3];
    910916\end{uC++}
    911917&
     
    917923};
    918924void main( @T & t@ ) {
    919         ... @resumeAt( partner, ExceptionInst( E, ... )@ );
     925        ... @resumeAt( partner, ExceptionInst( E, ... ) )@;
    920926        ... @active_thread();@ ...
    921927}
    922 \end{cfa}
    923 \\
    924 \multicolumn{2}{@{}l@{}}{\lstinline{T t; // start thread in main routine}}
     928T t;  // create thread object and start thread in main
     929processor p[3]; // 4 kernel threads including program main
     930\end{cfa}
    925931\end{tabular}
    926932\end{cquote}
     
    10091015        }
    10101016};
    1011 enum { N = 3 };
    1012 Barrier b{ N };
     1017Barrier b{ 3 };
    10131018\end{uC++}
    10141019&
     
    10341039        }
    10351040}
    1036 enum { N = 3 };
    1037 Barrier b{ N };
     1041Barrier b{ 3 };
    10381042\end{cfa}
    10391043\end{tabular}
     
    11781182
    11791183
    1180 {\lstset{tabsize=3}
     1184{\lstset{tabsize=4}
    11811185\setlength{\tabcolsep}{5pt}
    11821186\begin{tabular}{@{}l|ll@{}}
     
    11861190@Future_ISM@<double> fd;
    11871191struct Msg { int i, j; }; @Future_ISM@<Msg> fm;
    1188 struct Stop {}; @Future_ISM@<Stop> fs;
    11891192struct Cont {}; @Future_ISM@<Cont> fc;
     1193_Exception Stop {};
    11901194
    11911195_Task Worker {
    11921196        void main() {
    1193 
    1194                 for ( ;; ) {
    1195                         _Select( fi ) { cout << fi() << endl; fi.reset(); }
    1196                         and _Select( fd ) { cout << fd() << endl; fd.reset(); }
    1197                         and _Select( fm ) {
    1198                                 cout << fm().i << " " << fm().j << endl; fm.reset();
    1199                         } or _Select( fs ) { cout << "stop" << endl; break; }
    1200                         fc.delivery( (Cont){} );        // synchronize
    1201                 }
    1202         }
    1203 
     1197                try {
     1198                        for ( ;; ) {
     1199                                _Select( fi ) { cout << fi() << endl; fi.reset(); }
     1200                                and _Select( fd ) { cout << fd() << endl; fd.reset(); }
     1201                                and _Select( fm ) {
     1202                                        cout << fm().i << " " << fm().j << endl; fm.reset();
     1203                                }
     1204                                fc( (Cont){} );         // synchronize
     1205                        }
     1206                } catch( Stop & ) { cout << "stop" << endl;}
     1207        }
    12041208};
    12051209int main() {
    12061210        Worker worker;
    12071211        for ( int i = 0; i < 10; i += 1 ) {
    1208                 fi( i );   fd( i + 2.5 );   fm( (Msg){ i, 2 } ); // fulfil
     1212                fi( i );   fd( i + 2.5 );   fm( (Msg){ i, 2 } );  // fulfil
    12091213                fc(); fc.reset();                               // synchronize
    12101214        }
    1211         fs( (Stop){} );
     1215        fi( new Stop{} );                               // trigger exception
    12121216} // wait for worker to terminate
    12131217\end{uC++}
     
    12151219\begin{cfa}
    12161220#include <future.hfa>
    1217 @future_rc@(int) fi;
    1218 @future_rc@(double) fd;
    1219 struct Msg { int i, j; }; @future_rc@(Msg) fm;
    1220 struct Stop {}; @future_rc@(Stop) fs;
    1221 struct Cont {}; @future_rc@(Cont) fc;
    1222 ExceptionDecl( Break );
     1221@future_rc@( int ) fi;
     1222@future_rc@( double ) fd;
     1223struct Msg { int i, j; }; @future_rc@( Msg ) fm;
     1224struct Cont {}; @future_rc@( Cont ) fc;
     1225ExceptionDecl( Stop );
     1226
    12231227thread Worker {};
    12241228void main( Worker & ) {
     
    12271231                        waituntil( fi ) { sout | fi(); reset( fi ); }
    12281232                        and waituntil( fd ) { sout | fd(); reset( fd ); }
    1229                         and waituntil( fm ) { sout | fm().i | fm().j; reset( fm ); }
    1230                         or waituntil( fs ) { sout | "stop";
    1231                                 throw ExceptionInst( Break );
     1233                        and waituntil( fm ) {
     1234                                sout | fm().i | fm().j; reset( fm );
    12321235                        }
    12331236                        fc( (Cont){} );         // synchronize
    12341237                }
    1235         } catch( Break * ) {}
    1236 }
     1238        } catch( Stop * ) { sout | "stop"; }
     1239}
     1240
    12371241int main() {
    12381242        Worker worker;
    12391243        for ( i; 10 ) {
    1240                 fi( i );   fd( i + 2.5 );   fm( (Msg){ i, 2 } ); // fulfil
     1244                fi( i );   fd( i + 2.5 );   fm( (Msg){ i, 2 } );  // fulfil
    12411245                fc(); reset( fc );              // synchronize
    12421246        }
    1243         fs( (Stop){} );
     1247        fi( ExceptionPtr( ExceptionInst( Stop ) ) );
    12441248} // wait for worker to terminate
    12451249\end{cfa}
Note: See TracChangeset for help on using the changeset viewer.