#include <coroutine.hfa>
#include <fstream.hfa>

coroutine PingPong {
	const char * name;
	unsigned int N;
	PingPong & partner;
};

void ?{}( PingPong & this, const char * name, unsigned int N, PingPong & partner ) {
	this.[name, N] = [name, N];  &this.partner = &partner;
}
void ?{}( PingPong & this, const char * name, unsigned int N ) {
	this{ name, N, *0p };								// call first constructor
}
// void cycle( PingPong & pingpong ) {
// 	resume( pingpong );
// }
void partner( PingPong & this, PingPong & partner ) {
	&this.partner = &partner;
	resume( this );
}
void main( PingPong & pingpong ) with(pingpong) {		// ping's starter ::main, pong's starter ping
	for ( i; N ) {										// N ping-pongs
		sout | name | i;
//		cycle( partner );
		resume( partner );
	} // for
}
int main() {
	enum { N = 5 };
	PingPong ping = { "ping", N }, pong = { "pong", N, ping };
	partner( ping, pong );
}

// Local Variables: //
// tab-width: 4 //
// compile-command: "cfa Pingpong2.cfa" //
// End: //
