source: doc/papers/llheap/examples/Pingpong.cfa

Last change on this file was 7bef8cf, checked in by Peter A. Buhr <pabuhr@…>, 18 months ago

start paper on llheap

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