- File:
-
- 1 edited
-
doc/papers/concurrency/examples/Pingpong.cfa (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/concurrency/examples/Pingpong.cfa
r1e5d0f0c r17c6c1c3 4 4 coroutine PingPong { 5 5 const char * name; 6 unsigned int N;7 PingPong ∂6 /* const */ unsigned int N; 7 PingPong * part; 8 8 }; 9 9 10 10 void ?{}( PingPong & this, const char * name, unsigned int N, PingPong & part ) { 11 this.[name, N] = [name, N]; &this.part = ∂ 11 (this.__cor){name}; 12 this.name = name; 13 this.N = N; 14 this.part = ∂ 12 15 } 13 16 void ?{}( PingPong & this, const char * name, unsigned int N ) { 14 this{ name, N, * 0p }; // call first constructor17 this{ name, N, *(PingPong *)0 }; 15 18 } 16 19 void cycle( PingPong & pingpong ) { … … 18 21 } 19 22 void partner( PingPong & this, PingPong & part ) { 20 &this.part = ∂23 this.part = ∂ 21 24 resume( this ); 22 25 } 23 void main( PingPong & pingpong ) with(pingpong) {// ping's starter ::main, pong's starter ping24 for ( N ) {// N ping-pongs25 sout | name;26 cycle( part );26 void main( PingPong & pingpong ) { // ping's starter ::main, pong's starter ping 27 for ( pingpong.N ) { // N ping-pongs 28 sout | pingpong.name; 29 cycle( *pingpong.part ); 27 30 } // for 28 31 } 29 32 int main() { 30 enum { N = 5};33 enum { N = 20 }; 31 34 PingPong ping = { "ping", N }, pong = { "pong", N, ping }; 32 35 partner( ping, pong ); … … 35 38 // Local Variables: // 36 39 // tab-width: 4 // 37 // compile-command: "cfa Pingpong.cfa" //40 // compile-command: "cfa pingpong.cfa" // 38 41 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.