source: doc/papers/concurrency/examples/Pingpong.cfa @ 0087e0e

arm-ehcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-expr
Last change on this file since 0087e0e was 17c6c1c, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

add more paper examples

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