Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrency/actors/executor.cfa

    r7edf912 r77fd9fe2  
    1010static int ids = 0;
    1111struct d_actor {
    12         inline actor;
    13         d_actor * gstart;
    14         int id, rounds, recs, sends;
     12    inline actor;
     13    d_actor * gstart;
     14    int id, rounds, recs, sends;
    1515};
    1616void ?{}( d_actor & this ) with(this) {
    17         id = ids++;
    18         gstart = (&this + (id / Set * Set - id)); // remember group-start array-element
    19         rounds = Set * Rounds;  // send at least one message to each group member
    20         recs = 0;
    21         sends = 0;
     17    id = ids++;
     18    gstart = (&this + (id / Set * Set - id)); // remember group-start array-element
     19    rounds = Set * Rounds;      // send at least one message to each group member
     20    recs = 0;
     21    sends = 0;
    2222}
    2323
     
    2525
    2626allocation receive( d_actor & this, d_msg & msg ) with( this ) {
    27         if ( recs == rounds ) return Finished;
    28         if ( recs % Batch == 0 ) {
    29                 for ( i; Batch ) {
    30                         gstart[sends % Set] | shared_msg;
    31                         sends += 1;
    32                 }
    33         }
    34         recs += 1;
    35         return Nodelete;
     27    if ( recs == rounds ) return Finished;
     28    if ( recs % Batch == 0 ) {
     29        for ( i; Batch ) {
     30            gstart[sends % Set] | shared_msg;
     31            sends += 1;
     32        }
     33    }
     34    recs += 1;
     35    return Nodelete;
    3636}
    3737
    3838int main( int argc, char * argv[] ) {
    39         switch ( argc ) {
     39    switch ( argc ) {
    4040          case 7:
    4141                if ( strcmp( argv[6], "d" ) != 0 ) {                    // default ?
    42                         BufSize = ato( argv[6] );
    43                         if ( BufSize < 0 ) fallthru default;
     42                        BufSize = atoi( argv[6] );
     43                        if ( BufSize < 0 ) goto Usage;
    4444                } // if
    4545          case 6:
    4646                if ( strcmp( argv[5], "d" ) != 0 ) {                    // default ?
    47                         Batch = ato( argv[5] );
    48                         if ( Batch < 1 ) fallthru default;
     47                        Batch = atoi( argv[5] );
     48                        if ( Batch < 1 ) goto Usage;
    4949                } // if
    5050          case 5:
    5151                if ( strcmp( argv[4], "d" ) != 0 ) {                    // default ?
    52                         Processors = ato( argv[4] );
    53                         if ( Processors < 1 ) fallthru default;
     52                        Processors = atoi( argv[4] );
     53                        if ( Processors < 1 ) goto Usage;
    5454                } // if
    5555          case 4:
    5656                if ( strcmp( argv[3], "d" ) != 0 ) {                    // default ?
    57                         Rounds = ato( argv[3] );
    58                         if ( Rounds < 1 ) fallthru default;
     57                        Rounds = atoi( argv[3] );
     58                        if ( Rounds < 1 ) goto Usage;
    5959                } // if
    6060          case 3:
    6161                if ( strcmp( argv[2], "d" ) != 0 ) {                    // default ?
    62                         Set = ato( argv[2] );
    63                         if ( Set < 1 ) fallthru default;
     62                        Set = atoi( argv[2] );
     63                        if ( Set < 1 ) goto Usage;
    6464                } // if
    6565          case 2:
    6666                if ( strcmp( argv[1], "d" ) != 0 ) {                    // default ?
    67                         Actors = ato( argv[1] );
    68                         if ( Actors < 1 || Actors <= Set || Actors % Set != 0 ) fallthru default;
     67                        Actors = atoi( argv[1] );
     68                        if ( Actors < 1 || Actors <= Set || Actors % Set != 0 ) goto Usage;
    6969                } // if
    7070          case 1:                                                                                       // use defaults
    7171                break;
    7272          default:
    73                 exit | "Usage: " | argv[0]
    74                          | " [ actors (> 0 && > set && actors % set == 0 ) | 'd' (default " | Actors
     73          Usage:
     74                sout | "Usage: " | argv[0]
     75             | " [ actors (> 0 && > set && actors % set == 0 ) | 'd' (default " | Actors
    7576                         | ") ] [ set (> 0) | 'd' (default " | Set
    7677                         | ") ] [ rounds (> 0) | 'd' (default " | Rounds
     
    7980                         | ") ] [ buffer size (>= 0) | 'd' (default " | BufSize
    8081                         | ") ]" ;
     82                exit( EXIT_FAILURE );
    8183        } // switch
    8284
    83         executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * 512, true };
     85    executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * 512, true };
    8486
    85         sout | "starting";
     87    printf("starting\n");
    8688
    87         start_actor_system( e );
     89    start_actor_system( e );
    8890
    89         sout | "started";
     91    printf("started\n");
    9092
    91         d_actor actors[ Actors ];
     93    d_actor actors[ Actors ];
    9294
    9395        for ( i; Actors ) {
     
    9597        } // for
    9698
    97         sout | "stopping";
     99    printf("stopping\n");
    98100
    99         stop_actor_system();
     101    stop_actor_system();
    100102
    101         sout | "stopped";
     103    printf("stopped\n");
     104
     105    return 0;
    102106}
Note: See TracChangeset for help on using the changeset viewer.