Ignore:
Timestamp:
Nov 16, 2024, 6:32:00 PM (14 hours ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
95707a3
Parents:
489d3ba
Message:

more updates to the uC++toCFA document

File:
1 edited

Legend:

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

    r489d3ba re255902b  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Wed Nov 13 18:09:58 2024
    14 %% Update Count     : 6207
     13%% Last Modified On : Fri Nov 15 09:55:34 2024
     14%% Update Count     : 6249
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    357357
    358358
     359\section{Constructor / Destructor}
     360
     361\begin{cquote}
     362\begin{tabular}{@{}l|l@{}}
     363\begin{uC++}
     364
     365struct S {
     366        int i, j;
     367
     368        @S@( int i, int j ) { S::i = i; S::j = j; }
     369        @~S@() {}
     370};
     371S s1 = { 1, 2 };
     372
     373S * s2 = new S{ 1, 2 };
     374delete s2;
     375s2 = new S{ 1, 2 };
     376delete s2;
     377S & s3 = *new S{ 1, 2 };
     378delete &s3;
     379s3 = *new S{ 1, 2 };
     380delete &s3;
     381\end{uC++}
     382&
     383\begin{cfa}
     384#include <stdlib.hfa> // new (malloc)
     385struct S {
     386        int i, j;
     387};
     388void @?{}@( S & s, int i, int j ) { s.i = i; s.j = j; }
     389void @^?{}@( S & s ) { s.i = 0; s.j = 0; }     
     390
     391S s1 = { 1, 2 };
     392// cannot use 0/1 (zero_t/one_t) with "new"
     393S * s2 = new( 1@n@, 2 ); // n => (int)
     394delete( s2 );
     395s2 = new( 1n, 2 );
     396delete( s2 );
     397S & s3 = *new( 1n, 2 );
     398delete( s3 );
     399&s3 = &*new( 1n, 2 );
     400delete( s3 );
     401\end{cfa}
     402\end{tabular}
     403\end{cquote}
     404
     405
    359406\section{\texorpdfstring{Structures (object-oriented \protect\vs routine style)}{Structures (object-oriented vs. routine style)}}
    360407
     
    381428setter( @s,@ 3 );  // normal calls
    382429int k = getter( @s@ );
    383 \end{cfa}
    384 \end{tabular}
    385 \end{cquote}
    386 
    387 
    388 \section{Constructor / Destructor}
    389 
    390 \begin{cquote}
    391 \begin{tabular}{@{}l|l@{}}
    392 \begin{uC++}
    393 
    394 struct S {
    395         int i, j;
    396         @S@( int i, int j ) { S::i = i; S::j = j; }
    397         @~S@() {}
    398 };
    399 S s = { 1, 2 }, s2{ 1, 2 };
    400 S * s3 = new S{ 1, 2 };
    401 S & s4 = *new S{ 1, 2 };
    402 \end{uC++}
    403 &
    404 \begin{cfa}
    405 #include <stdlib.hfa> // malloc
    406 struct S {
    407         int i, j;
    408 };
    409 void @?{}( S & s@, int i, int j ) { s.[i, j] = [i, j]; }
    410 void @^?{}( S & s@ ) {}
    411 S s = { 1, 2 }, s2{ 1, 2 };
    412 S * s3 = &(*malloc()){ 1, 2 };
    413 S & s4 = (*malloc()){ 1, 2 }; // fails
    414430\end{cfa}
    415431\end{tabular}
     
    734750                : @public uBarrier@ { // inheritance
    735751        int total;
     752        void @last@() { cout << total << endl; }
    736753  public:
    737754        Barrier( unsigned int group ) :
     
    740757        }
    741758        void @block@( int subtotal ) {
     759
     760
    742761                total += subtotal;
    743762                @uBarrier::block();@
    744763        }
    745   private:
    746         void @last@() { cout << total << endl; }
    747764};
    748765enum { N = 3 };
     
    770787        @barrier b;@                    // containment
    771788        int total;
     789
    772790};
    773791void ?{}( Barrier & B, unsigned int group ) with(B) {
     
    776794}
    777795unsigned int block( Barrier & B, int subtotal ) with(B) {
    778         @mutex( b )@ {  total += subtotal; } // use barrier's mutual exclusion
    779796        void @last@() { sout | total; } // called by Gth arriving thread
    780         @block@( b, last ); // wait for barrier trigger
    781 }
    782 
    783 
     797        @mutex( b )@ {  // use barrier's mutual exclusion
     798                total += subtotal;
     799                return @block@( b, last ); // wait for barrier trigger
     800        }
     801}
    784802enum { N = 3 };
    785803Barrier b{ N };
     
    871889\enlargethispage{1000pt}
    872890
     891\noindent
    873892External Scheduling
    874893\begin{cquote}
Note: See TracChangeset for help on using the changeset viewer.