source: doc/papers/concurrency/examples/Pingpong.cfa@ 8dbfb7e

ADT arm-eh ast-experimental cleanup-dtors enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 8dbfb7e was 17c6c1c3, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

add more paper examples

  • Property mode set to 100644
File size: 955 bytes
RevLine 
[17c6c1c3]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.