source: tests/concurrency/actors/pingpong.cfa@ 0497b6ba

Last change on this file since 0497b6ba was 41882628, checked in by Peter A. Buhr <pabuhr@…>, 10 months ago

update test programs with actor name change

  • Property mode set to 100644
File size: 1.1 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 {
[7edf912]12 inline message;
13 size_t count;
[1c75ef8]14};
[7edf912]15//static inline void ?{}( p_msg & this ) { ((message &)this){}; this.count = 0; }
16static inline void ?{}( p_msg & this ) { this.count = 0; }
[1c75ef8]17
18ping * pi;
19pong * po;
20size_t times = 100000;
21
[c880a7b]22allocation 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]32allocation 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
42size_t Processors = 2;
43
44int main( int argc, char * argv[] ) {
[7edf912]45 sout | "start";
[1c75ef8]46
[7edf912]47 processor p[Processors - 1];
[1c75ef8]48
[41882628]49 actor_start( Processors ); // test passing number of processors
[7edf912]50 ping pi_actor;
51 pong po_actor;
52 po = &po_actor;
53 pi = &pi_actor;
54 p_msg m;
55 pi_actor | m;
[41882628]56 actor_stop();
[1c75ef8]57
[7edf912]58 sout | "end";
[50be8af5]59}
Note: See TracBrowser for help on using the repository browser.