source: tests/concurrency/actors/pingpong.cfa @ 7e4bd9b6

Last change on this file since 7e4bd9b6 was c880a7b, checked in by caparsons <caparson@…>, 17 months ago

refactored tests to use new name for allocation enum

  • 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
[c880a7b]21allocation receive( ping & receiver, p_msg & msg ) {
[1c75ef8]22    msg.count++;
23    if ( msg.count > times ) return Finished;
24
[c880a7b]25    allocation retval = Nodelete;
[1c75ef8]26    if ( msg.count == times ) retval = Finished;
[809e058]27    *po << msg;
[1c75ef8]28    return retval;
29}
30
[c880a7b]31allocation receive( pong & receiver, p_msg & msg ) {
[1c75ef8]32    msg.count++;
33    if ( msg.count > times ) return Finished;
34   
[c880a7b]35    allocation retval = Nodelete;
[1c75ef8]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.