source: doc/papers/concurrency/examples/Pingpong.cfa @ d7a02ae

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

first complete draft of new concurrency paper

  • Property mode set to 100644
File size: 946 bytes
RevLine 
[17c6c1c]1#include <coroutine.hfa>
2#include <fstream.hfa>
3
4coroutine PingPong {
5        const char * name;
[1e5d0f0c]6        unsigned int N;
7        PingPong & part;
[17c6c1c]8};
9
[d7a02ae]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// }
[17c6c1c]16void cycle( PingPong & pingpong ) {
17        resume( pingpong );
18}
19void partner( PingPong & this, PingPong & part ) {
[1e5d0f0c]20        &this.part = &part;
[17c6c1c]21        resume( this );
22}
[1e5d0f0c]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 );
[17c6c1c]27        } // for
28}
29int main() {
[1e5d0f0c]30        enum { N = 5 };
[17c6c1c]31        PingPong ping = { "ping", N }, pong = { "pong", N, ping };
32        partner( ping, pong );
33}
34
35// Local Variables: //
36// tab-width: 4 //
[1e5d0f0c]37// compile-command: "cfa Pingpong.cfa" //
[17c6c1c]38// End: //
Note: See TracBrowser for help on using the repository browser.