Last change
on this file since b29a1e8 was
64e3ac7,
checked in by Peter A. Buhr <pabuhr@…>, 14 months ago
|
harmonize name for fibonacci_nonlocal and pingpong_nonlocal
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Rev | Line | |
---|
[bef2245] | 1 | #include <fstream.hfa> |
---|
| 2 | #include <thread.hfa> |
---|
| 3 | #include <coroutine.hfa> |
---|
| 4 | #include <stdlib.hfa> |
---|
| 5 | #include <fstream.hfa> |
---|
| 6 | |
---|
| 7 | exception num_pings { int num; }; |
---|
| 8 | vtable(num_pings) num_pings_vt; |
---|
| 9 | |
---|
| 10 | exception num_pongs { int num; }; |
---|
| 11 | vtable(num_pongs) num_pongs_vt; |
---|
| 12 | |
---|
| 13 | thread Ping; |
---|
| 14 | thread Pong { Ping & p; int cnt; }; |
---|
| 15 | thread Ping { Pong & p; int cnt; }; |
---|
| 16 | |
---|
| 17 | int numtimes = 100000; |
---|
| 18 | |
---|
| 19 | void main( Pong & this ) with(this) { |
---|
| 20 | try { |
---|
| 21 | for ( ;; ) { |
---|
| 22 | while( !poll( this ) ) {} |
---|
| 23 | num_pongs except{ &num_pongs_vt, cnt + 1 }; |
---|
| 24 | resumeAt( p, except ); |
---|
| 25 | } |
---|
| 26 | } catchResume ( num_pings * e; e->num < numtimes ) { |
---|
| 27 | cnt = e->num; |
---|
| 28 | } catch( num_pings * e ) { |
---|
| 29 | if ( e->num == numtimes ){ |
---|
| 30 | num_pongs except{ &num_pongs_vt, e->num + 1 }; |
---|
| 31 | resumeAt( p, except ); |
---|
| 32 | } |
---|
| 33 | } |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | void main( Ping & this ) with(this) { |
---|
| 37 | try { |
---|
| 38 | for ( ;; ) { |
---|
| 39 | while( !poll( this ) ) {} |
---|
| 40 | num_pings except{ &num_pings_vt, cnt + 1 }; |
---|
| 41 | resumeAt( p, except ); |
---|
| 42 | } |
---|
| 43 | } catchResume ( num_pongs * e; e->num < numtimes ) { |
---|
| 44 | cnt = e->num; |
---|
| 45 | } catch( num_pongs * e ) { |
---|
| 46 | if ( e->num == numtimes ){ |
---|
| 47 | num_pings except{ &num_pings_vt, e->num + 1 }; |
---|
| 48 | resumeAt( p, except ); |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | int main() { |
---|
| 54 | processor p; |
---|
| 55 | sout | "start"; |
---|
| 56 | { |
---|
| 57 | Ping ping; |
---|
| 58 | Pong pong; |
---|
| 59 | &ping.p = &pong; |
---|
| 60 | &pong.p = &ping; |
---|
| 61 | num_pings except{ &num_pings_vt, 0 }; |
---|
| 62 | resumeAt( pong, except ); |
---|
| 63 | } |
---|
| 64 | sout | "done"; |
---|
| 65 | } |
---|
| 66 | |
---|
Note: See
TracBrowser
for help on using the repository browser.