source: doc/papers/concurrency/examples/Pingpong2.cfa @ b797fe36

Last change on this file since b797fe36 was 466fa01, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

add diagrams and example programs

  • Property mode set to 100644
File size: 991 bytes
Line 
1#include <coroutine.hfa>
2#include <fstream.hfa>
3
4coroutine PingPong {
5        const char * name;
6        unsigned int N;
7        PingPong & partner;
8};
9
10void ?{}( PingPong & this, const char * name, unsigned int N, PingPong & partner ) {
11        this.[name, N] = [name, N];  &this.partner = &partner;
12}
13void ?{}( PingPong & this, const char * name, unsigned int N ) {
14        this{ name, N, *0p };                                                           // call first constructor
15}
16// void cycle( PingPong & pingpong ) {
17//      resume( pingpong );
18// }
19void partner( PingPong & this, PingPong & partner ) {
20        &this.partner = &partner;
21        resume( this );
22}
23void main( PingPong & pingpong ) with(pingpong) {               // ping's starter ::main, pong's starter ping
24        for ( i; N ) {                                                                          // N ping-pongs
25                sout | name | i;
26//              cycle( partner );
27                resume( partner );
28        } // for
29}
30int main() {
31        enum { N = 5 };
32        PingPong ping = { "ping", N }, pong = { "pong", N, ping };
33        partner( ping, pong );
34}
35
36// Local Variables: //
37// tab-width: 4 //
38// compile-command: "cfa Pingpong2.cfa" //
39// End: //
Note: See TracBrowser for help on using the repository browser.