#include #include #include exception num_ping_pongs { int num; }; vtable(num_ping_pongs) num_ping_pongs_vt; thread Ping_Pong { char * name; int cnt; num_ping_pongs except; Ping_Pong & partner; }; void ?{}( Ping_Pong & this, char * name ) with( this ) { this.name = name; cnt = 0; ?{}( except, &num_ping_pongs_vt, 0 ); } void main( Ping_Pong & this ) with( this ) { enum { numtimes = 100 }; void inc_resume_at( int value ) { except.num = value + 1; resumeAt( partner, except ); } try { for () { while( ! poll( this ) ) { yield(); } inc_resume_at( cnt ); } } catchResume( num_ping_pongs * e; e->num < numtimes ) { mutex( sout ) sout | name | "catchResume" | cnt | e->num; cnt = e->num; } catch( num_ping_pongs * e ) { mutex( sout ) sout | name | "catch" | cnt | e->num; if ( e->num == numtimes ) { inc_resume_at( e->num ); } } } int main() { processor p; sout | "main start"; { Ping_Pong ping { "ping" }, pong{ "pong" }; &ping.partner = &pong; // create cycle &pong.partner = &ping; num_ping_pongs except{ &num_ping_pongs_vt, 0 }; resumeAt( pong, except ); } sout | "main end"; }