source:
tests/concurrency/actors/pingpong.cfa
@
876739f
Last change on this file since 876739f was 7edf912, checked in by , 14 months ago | |
---|---|
|
|
File size: 1.2 KB |
Rev | Line | |
---|---|---|
[1c75ef8] | 1 | #include <fstream.hfa> |
2 | #include <stdlib.hfa> | |
3 | #include <string.h> | |
4 | #include <stdio.h> | |
5 | #include <mutex_stmt.hfa> | |
6 | #include <actor.hfa> | |
7 | ||
[4933f18] | 8 | struct ping { inline actor; }; |
9 | struct pong { inline actor; }; | |
[1c75ef8] | 10 | |
11 | struct p_msg { | |
[7edf912] | 12 | inline message; |
13 | size_t count; | |
[1c75ef8] | 14 | }; |
[7edf912] | 15 | //static inline void ?{}( p_msg & this ) { ((message &)this){}; this.count = 0; } |
16 | static inline void ?{}( p_msg & this ) { this.count = 0; } | |
[1c75ef8] | 17 | |
18 | ping * pi; | |
19 | pong * po; | |
20 | size_t times = 100000; | |
21 | ||
[c880a7b] | 22 | allocation receive( ping & receiver, p_msg & msg ) { |
[7edf912] | 23 | msg.count++; |
24 | if ( msg.count > times ) return Finished; | |
[1c75ef8] | 25 | |
[7edf912] | 26 | allocation retval = Nodelete; |
27 | if ( msg.count == times ) retval = Finished; | |
28 | *po | msg; | |
29 | return retval; | |
[1c75ef8] | 30 | } |
31 | ||
[c880a7b] | 32 | allocation receive( pong & receiver, p_msg & msg ) { |
[7edf912] | 33 | msg.count++; |
34 | if ( msg.count > times ) return Finished; | |
35 | ||
36 | allocation retval = Nodelete; | |
37 | if ( msg.count == times ) retval = Finished; | |
38 | *pi | msg; | |
39 | return retval; | |
[1c75ef8] | 40 | } |
41 | ||
42 | size_t Processors = 2; | |
43 | ||
44 | int main( int argc, char * argv[] ) { | |
[7edf912] | 45 | sout | "start"; |
[1c75ef8] | 46 | |
[7edf912] | 47 | processor p[Processors - 1]; |
[1c75ef8] | 48 | |
[7edf912] | 49 | start_actor_system( Processors ); // test passing number of processors |
50 | ping pi_actor; | |
51 | pong po_actor; | |
52 | po = &po_actor; | |
53 | pi = &pi_actor; | |
54 | p_msg m; | |
55 | pi_actor | m; | |
56 | stop_actor_system(); | |
[1c75ef8] | 57 | |
[7edf912] | 58 | sout | "end"; |
[50be8af] | 59 | } |
Note: See TracBrowser
for help on using the repository browser.