Last change
on this file since de3a579 was
7bef8cf,
checked in by Peter A. Buhr <pabuhr@…>, 18 months ago
|
start paper on llheap
|
-
Property mode set to
100644
|
File size:
807 bytes
|
Rev | Line | |
---|
[7bef8cf] | 1 | #include <iostream> |
---|
| 2 | using namespace std; |
---|
| 3 | |
---|
| 4 | _Coroutine PingPong { |
---|
| 5 | const char * name; |
---|
| 6 | const unsigned int N; |
---|
| 7 | PingPong * part; |
---|
| 8 | void main() { // ping’s starter ::main, pong’s starter ping |
---|
| 9 | for ( unsigned int i = 0; i < N; i += 1 ) { |
---|
| 10 | cout << name << endl; |
---|
| 11 | part->cycle(); |
---|
| 12 | } |
---|
| 13 | } |
---|
| 14 | public: |
---|
| 15 | PingPong( const char * name, unsigned int N, PingPong & part ) |
---|
| 16 | : name( name ), N( N ), part( & part ) {} |
---|
| 17 | PingPong( const char * name, unsigned int N ) : name( name ), N( N ) {} |
---|
| 18 | void partner( PingPong & part ) { PingPong::part = ∂ } |
---|
| 19 | void cycle() { resume(); } |
---|
| 20 | }; |
---|
| 21 | int main() { |
---|
| 22 | enum { N = 10 }; |
---|
| 23 | PingPong ping( "ping", N ), pong( "pong", N, ping ); |
---|
| 24 | ping.partner( pong ); |
---|
| 25 | ping.cycle(); |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | // Local Variables: // |
---|
| 29 | // tab-width: 4 // |
---|
| 30 | // compile-command: "u++-work -O2 -nodebug Pingpong.cc" // |
---|
| 31 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.