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