source:
tests/concurrency/actors/dynamic.cfa@
2214e81
| Last change on this file since 2214e81 was d96f7c4, checked in by , 10 months ago | |
|---|---|
|
|
| File size: 1.2 KB | |
| Rev | Line | |
|---|---|---|
| [dab2b6a] | 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 |
| [dab2b6a] | 8 | |
| [4933f18] | 9 | struct derived_actor { inline actor; }; |
| [dab2b6a] | 10 | struct derived_msg { |
| [7edf912] | 11 | inline message; |
| 12 | int cnt; | |
| [dab2b6a] | 13 | }; |
| 14 | ||
| 15 | void ?{}( derived_msg & this, int cnt ) { | |
| [7edf912] | 16 | set_allocation( this, Delete ); |
| 17 | this.cnt = cnt; | |
| [dab2b6a] | 18 | } |
| 19 | void ?{}( derived_msg & this ) { ((derived_msg &)this){ 0 }; } | |
| 20 | ||
| [6a6e205] | 21 | allocation receive( derived_actor &, derived_msg & msg ) { |
| [7edf912] | 22 | if ( msg.cnt >= Times ) { |
| 23 | sout | "Done"; | |
| 24 | return Delete; | |
| 25 | } | |
| 26 | derived_msg * d_msg = alloc(); | |
| 27 | (*d_msg){ msg.cnt + 1 }; | |
| 28 | derived_actor * d_actor = alloc(); | |
| 29 | (*d_actor){}; | |
| 30 | *d_actor | *d_msg; | |
| 31 | return Delete; | |
| [dab2b6a] | 32 | } |
| 33 | ||
| 34 | int main( int argc, char * argv[] ) { | |
| [7edf912] | 35 | switch ( argc ) { |
| [dab2b6a] | 36 | case 2: |
| 37 | if ( strcmp( argv[1], "d" ) != 0 ) { // default ? | |
| [50be8af5] | 38 | Times = ato( argv[1] ); |
| [d96f7c4] | 39 | if ( Times < 1 ) fallthrough default; |
| [dab2b6a] | 40 | } // if |
| 41 | case 1: // use defaults | |
| 42 | break; | |
| 43 | default: | |
| [50be8af5] | 44 | exit | "Usage: " | argv[0] | " [ times (> 0) ]"; |
| [dab2b6a] | 45 | } // switch |
| 46 | ||
| [7edf912] | 47 | sout | "starting"; |
| [dab2b6a] | 48 | |
| [7edf912] | 49 | executor e{ 0, 1, 1, false }; |
| [41882628] | 50 | actor_start( e ); |
| [7edf912] | 51 | sout | "started"; |
| [dab2b6a] | 52 | |
| [7edf912] | 53 | derived_msg * d_msg = alloc(); |
| 54 | (*d_msg){}; | |
| 55 | derived_actor * d_actor = alloc(); | |
| 56 | (*d_actor){}; | |
| 57 | *d_actor | *d_msg; | |
| [dab2b6a] | 58 | |
| [41882628] | 59 | actor_stop(); |
| [7edf912] | 60 | sout | "stopped"; |
| [50be8af5] | 61 | } |
Note:
See TracBrowser
for help on using the repository browser.