source: tests/exceptions/pingpong_nonlocal.cfa @ c54ca97

Last change on this file since c54ca97 was a2eb21a, checked in by Peter A. Buhr <pabuhr@…>, 16 months ago

fix problems in pingpong_nonlocal

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#include <fstream.hfa>
2#include <thread.hfa>
3#include <fstream.hfa>
4#include <mutex_stmt.hfa>
5
6exception num_ping_pongs { int num; };
7vtable(num_ping_pongs) num_ping_pongs_vt;
8
9thread Ping_Pong {
10        char * name;
11        int cnt;
12        num_ping_pongs except;
13        Ping_Pong & partner;
14};
15
16void ?{}( Ping_Pong & this, char * name ) with( this ) {
17        this.name = name;
18        cnt = 0;
19        ?{}( except, &num_ping_pongs_vt, 0 );
20}
21
22int numtimes = 100;
23
24void main( Ping_Pong & this ) with( this ) {
25        void inc_resume_at( int value ) {
26                except.num = value + 1;
27                resumeAt( partner, except );
28        }
29        mutex( sout ) sout | name | "start";
30        try {
31                for () {
32                        while( ! poll( this ) ) { yield(); }
33            inc_resume_at( cnt );
34                }
35        } catchResume( num_ping_pongs * e; e->num < numtimes ) {
36                mutex( sout ) sout | name | "catchResume" | cnt | e->num;
37                cnt = e->num;
38        } catch( num_ping_pongs * e ) {
39                mutex( sout ) sout | name | "catch" | cnt | e->num;
40                if ( e->num == numtimes ) {
41            inc_resume_at( e->num );
42                }
43        }
44        mutex( sout ) sout | name | "end";
45}
46
47int main() {
48        processor p;
49        sout | "main start";
50        {
51                Ping_Pong ping { "ping" }, pong{ "pong" };
52                &ping.partner = &pong;                                                  // create cycle
53                &pong.partner = &ping;
54                num_ping_pongs except{ &num_ping_pongs_vt, 0 };
55                resumeAt( pong, except );
56        }
57        sout | "main end";
58}
Note: See TracBrowser for help on using the repository browser.