source: tests/concurrency/actors/static.cfa @ f90c092

Last change on this file since f90c092 was 9cbdc13, checked in by caparson <caparson@…>, 12 months ago

removed print from static and dynamic tests that could be reordered due to a race

  • Property mode set to 100644
File size: 1.1 KB
Line 
1#include <actor.hfa>
2#include <fstream.hfa>
3#include <stdlib.hfa>
4#include <string.h>
5#include <stdio.h>
6
7int Times = 1000000;                                                            // default values
8
9struct derived_actor { inline actor; };
10struct derived_msg {
11        inline message;
12        int cnt;
13};
14
15void ?{}( derived_msg & this, int cnt ) {
16        set_allocation( this, Nodelete );
17        this.cnt = cnt;
18}
19void ?{}( derived_msg & this ) { ((derived_msg &)this){ 0 }; }
20
21allocation receive( derived_actor & receiver, derived_msg & msg ) {
22        if ( msg.cnt >= Times ) {
23                sout | "Done";
24                return Finished;
25        }
26        msg.cnt++;
27        receiver | msg;
28        return Nodelete;
29}
30
31int main( int argc, char * argv[] ) {
32        switch ( argc ) {
33          case 2:
34                if ( strcmp( argv[1], "d" ) != 0 ) {                    // default ?
35                        Times = ato( argv[1] );
36                        if ( Times < 1 ) fallthru default;
37                } // if
38          case 1:                                                                                       // use defaults
39                break;
40          default:
41                exit | "Usage: " | argv[0] | " [ times (> 0) ]";
42        } // switch
43
44        sout | "starting";
45
46        executor e{ 0, 1, 1, false };
47        start_actor_system( e );
48
49        sout | "started";
50
51        derived_msg msg;
52
53        derived_actor actor;
54
55        actor | msg;
56
57        stop_actor_system();
58
59        sout | "stopped";
60}
Note: See TracBrowser for help on using the repository browser.