source: tests/concurrency/actors/pingpong.cfa @ 0794365

ast-experimental
Last change on this file since 0794365 was c26bea2a, checked in by Peter A. Buhr <pabuhr@…>, 14 months ago

first attempt at renaming directory tests/concurrent to tests/concurrency to harmonize with other concurrency directory names

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