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