source: tests/concurrent/actors/types.cfa @ 418882a

ADTast-experimental
Last change on this file since 418882a was 418882a, checked in by caparsons <caparson@…>, 15 months ago

added two actor tests. More to come

  • Property mode set to 100644
File size: 2.9 KB
Line 
1#include <actor.hfa>
2#include <fstream.hfa>
3#include <stdlib.hfa>
4#include <string.h>
5#include <stdio.h>
6#include <mutex_stmt.hfa>
7
8struct derived_actor {
9    inline actor;
10    int counter;
11};
12static inline void ?{}( derived_actor & this ) { ((actor &)this){}; this.counter = 0; }
13
14struct d_msg {
15    inline message;
16    int num;
17};
18static inline void ?{}( d_msg & this ) { ((message &)this){}; }
19
20// this isn't a valid receive routine since int is not a message type
21Allocation receive( derived_actor & receiver, int i ) with( receiver ) {
22    mutex(sout) sout | i;
23    counter++;
24    if ( counter == 2 ) return Finished;
25    return Nodelete;
26}
27
28Allocation receive( derived_actor & receiver, d_msg & msg ) {
29    return receive( receiver, msg.num );
30}
31
32struct derived_actor2 {
33    inline actor;
34};
35static inline void ?{}( derived_actor2 & this ) { ((actor &)this){}; }
36
37Allocation receive( derived_actor2 & receiver, d_msg & msg ) {
38    mutex(sout) sout | msg.num;
39    return Finished;
40}
41
42struct derived_actor3 {
43    inline actor;
44};
45static inline void ?{}( derived_actor3 & this ) { ((actor &)this){}; }
46
47struct d_msg2 {
48    inline message;
49    int num;
50};
51static inline void ?{}( d_msg2 & this ) { ((message &)this){}; }
52
53Allocation receive( derived_actor3 & receiver, d_msg & msg ) {
54    mutex(sout) sout | msg.num;
55    if ( msg.num == -1 ) return Nodelete;
56    return Finished;
57}
58
59Allocation receive( derived_actor3 & receiver, d_msg2 & msg ) {
60    mutex(sout) sout | msg.num;
61    return Finished;
62}
63
64size_t Processors = 3;
65
66int main( int argc, char * argv[] ) {
67    printf("start\n");
68
69    processor p[Processors - 1];
70
71    printf("basic test\n");
72    start_actor_system( Processors ); // test passing number of processors
73    derived_actor a;
74    d_msg b, c;
75    b.num = 1;
76    c.num = 2;
77    a | b | c;
78    stop_actor_system();
79
80    printf("same message and different actors test\n");
81    start_actor_system(); // let system detect # of processors
82    derived_actor2 d_ac2_0, d_ac2_1;
83    d_msg d_ac2_msg;
84    d_ac2_msg.num = 3;
85    d_ac2_0 | d_ac2_msg;
86    d_ac2_1 | d_ac2_msg;
87    stop_actor_system();
88
89   
90    {
91        printf("same message and different actor types test\n");
92        executor e{ 0, Processors, Processors == 1 ? 1 : Processors * 4, false };
93        start_actor_system( e ); // pass an explicit executor
94        derived_actor2 d_ac2_2;
95        derived_actor3 d_ac3_0;
96        d_msg d_ac23_msg;
97        d_ac23_msg.num = 4;
98        d_ac3_0 | d_ac23_msg;
99        d_ac2_2 | d_ac23_msg;
100        stop_actor_system();
101    } // RAII to clean up executor
102
103    {
104        printf("different message types, one actor test\n");
105        executor e{ 1, Processors, Processors == 1 ? 1 : Processors * 4, true };
106        start_actor_system( Processors );
107        derived_actor3 a3;
108        d_msg b1;
109        d_msg2 c2;
110        b1.num = -1;
111        c2.num = 5;
112        a3 | b1 | c2;
113        stop_actor_system();
114    } // RAII to clean up executor
115
116    printf("end\n");
117    return 0;
118}
Note: See TracBrowser for help on using the repository browser.