source: tests/concurrent/actors/pingpong.cfa @ 5c473c9

ADTast-experimental
Last change on this file since 5c473c9 was 1c75ef8, checked in by caparsons <caparson@…>, 21 months ago

added pingpong test

  • Property mode set to 100644
File size: 1.3 KB
Line 
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
8struct ping {
9    inline actor;
10};
11static inline void ?{}( ping & this ) { ((actor &)this){}; }
12
13struct pong {
14    inline actor;
15};
16static inline void ?{}( pong & this ) { ((actor &)this){}; }
17
18struct p_msg {
19    inline message;
20    size_t count;
21};
22static inline void ?{}( p_msg & this ) { ((message &)this){}; this.count = 0; }
23
24ping * pi;
25pong * po;
26size_t times = 100000;
27
28Allocation receive( ping & receiver, p_msg & msg ) {
29    msg.count++;
30    if ( msg.count > times ) return Finished;
31
32    Allocation retval = Nodelete;
33    if ( msg.count == times ) retval = Finished;
34    *po | msg;
35    return retval;
36}
37
38Allocation receive( pong & receiver, p_msg & msg ) {
39    msg.count++;
40    if ( msg.count > times ) return Finished;
41   
42    Allocation retval = Nodelete;
43    if ( msg.count == times ) retval = Finished;
44    *pi | msg;
45    return retval;
46}
47
48size_t Processors = 2;
49
50int main( int argc, char * argv[] ) {
51    printf("start\n");
52
53    processor p[Processors - 1];
54
55    start_actor_system( Processors ); // test passing number of processors
56
57    ping pi_actor;
58    pong po_actor;
59    po = &po_actor;
60    pi = &pi_actor;
61    p_msg m;
62    pi_actor | m;
63    stop_actor_system();
64
65    printf("end\n");
66    return 0;
67}
Note: See TracBrowser for help on using the repository browser.