Last change
on this file since bfa7bf0 was
7bef8cf,
checked in by Peter A. Buhr <pabuhr@…>, 18 months ago
|
start paper on llheap
|
-
Property mode set to
100644
|
File size:
991 bytes
|
Rev | Line | |
---|
[7bef8cf] | 1 | #include <coroutine.hfa> |
---|
| 2 | #include <fstream.hfa> |
---|
| 3 | |
---|
| 4 | coroutine PingPong { |
---|
| 5 | const char * name; |
---|
| 6 | unsigned int N; |
---|
| 7 | PingPong & partner; |
---|
| 8 | }; |
---|
| 9 | |
---|
| 10 | void ?{}( PingPong & this, const char * name, unsigned int N, PingPong & partner ) { |
---|
| 11 | this.[name, N] = [name, N]; &this.partner = &partner; |
---|
| 12 | } |
---|
| 13 | void ?{}( PingPong & this, const char * name, unsigned int N ) { |
---|
| 14 | this{ name, N, *0p }; // call first constructor |
---|
| 15 | } |
---|
| 16 | // void cycle( PingPong & pingpong ) { |
---|
| 17 | // resume( pingpong ); |
---|
| 18 | // } |
---|
| 19 | void partner( PingPong & this, PingPong & partner ) { |
---|
| 20 | &this.partner = &partner; |
---|
| 21 | resume( this ); |
---|
| 22 | } |
---|
| 23 | void main( PingPong & pingpong ) with(pingpong) { // ping's starter ::main, pong's starter ping |
---|
| 24 | for ( i; N ) { // N ping-pongs |
---|
| 25 | sout | name | i; |
---|
| 26 | // cycle( partner ); |
---|
| 27 | resume( partner ); |
---|
| 28 | } // for |
---|
| 29 | } |
---|
| 30 | int main() { |
---|
| 31 | enum { N = 5 }; |
---|
| 32 | PingPong ping = { "ping", N }, pong = { "pong", N, ping }; |
---|
| 33 | partner( ping, pong ); |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | // Local Variables: // |
---|
| 37 | // tab-width: 4 // |
---|
| 38 | // compile-command: "cfa Pingpong2.cfa" // |
---|
| 39 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.