source: tests/concurrent/actors/pingpong.cfa @ 85e49a6

ADTast-experimental
Last change on this file since 85e49a6 was 4933f18, checked in by caparsons <caparson@…>, 20 months ago

added test case to types test and refactored to remove redundant ctor calls

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[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]8struct ping { inline actor; };
9struct pong { inline actor; };
[1c75ef8]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;
[809e058]27    *po << msg;
[1c75ef8]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;
[809e058]37    *pi << msg;
[1c75ef8]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;
[809e058]55    pi_actor << m;
[1c75ef8]56    stop_actor_system();
57
58    printf("end\n");
59    return 0;
60}
Note: See TracBrowser for help on using the repository browser.