#include #include coroutine PingPong { const char * name; /* const */ unsigned int N; PingPong * part; }; void ?{}( PingPong & this, const char * name, unsigned int N, PingPong & part ) { (this.__cor){name}; this.name = name; this.N = N; this.part = ∂ } void ?{}( PingPong & this, const char * name, unsigned int N ) { this{ name, N, *(PingPong *)0 }; } void cycle( PingPong & pingpong ) { resume( pingpong ); } void partner( PingPong & this, PingPong & part ) { this.part = ∂ resume( this ); } void main( PingPong & pingpong ) { // ping's starter ::main, pong's starter ping for ( pingpong.N ) { // N ping-pongs sout | pingpong.name; cycle( *pingpong.part ); } // for } int main() { enum { N = 20 }; PingPong ping = { "ping", N }, pong = { "pong", N, ping }; partner( ping, pong ); } // Local Variables: // // tab-width: 4 // // compile-command: "cfa pingpong.cfa" // // End: //