#include #include #include #include #include exception num_pings { int num; }; vtable(num_pings) num_pings_vt; exception num_pongs { int num; }; vtable(num_pongs) num_pongs_vt; thread Ping; thread Pong { Ping & p; int cnt; }; thread Ping { Pong & p; int cnt; }; int numtimes = 100000; void main( Pong & this ) with(this) { try { for ( ;; ) { while( !poll( this ) ) {} num_pongs except{ &num_pongs_vt, cnt + 1 }; resumeAt( p, except ); } } catchResume ( num_pings * e; e->num < numtimes ) { cnt = e->num; } catch( num_pings * e ) { if ( e->num == numtimes ){ num_pongs except{ &num_pongs_vt, e->num + 1 }; resumeAt( p, except ); } } } void main( Ping & this ) with(this) { try { for ( ;; ) { while( !poll( this ) ) {} num_pings except{ &num_pings_vt, cnt + 1 }; resumeAt( p, except ); } } catchResume ( num_pongs * e; e->num < numtimes ) { cnt = e->num; } catch( num_pongs * e ) { if ( e->num == numtimes ){ num_pings except{ &num_pings_vt, e->num + 1 }; resumeAt( p, except ); } } } int main() { processor p; sout | "start"; { Ping ping; Pong pong; &ping.p = &pong; &pong.p = &ping; num_pings except{ &num_pings_vt, 0 }; resumeAt( pong, except ); } sout | "done"; }