source: doc/papers/llheap/examples/Pingpong2.cfa @ 7bef8cf

ADTast-experimental
Last change on this file since 7bef8cf was 7bef8cf, checked in by Peter A. Buhr <pabuhr@…>, 17 months ago

start paper on llheap

  • 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.