source: doc/papers/concurrency/examples/Pingpong.cfa @ 98d4df9

ADTarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 98d4df9 was 1e5d0f0c, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

start rewrite of coroutine section

  • Property mode set to 100644
File size: 928 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
10void ?{}( PingPong & this, const char * name, unsigned int N, PingPong & part ) {
11        this.[name, N] = [name, N];  &this.part = &part;
12}
13void ?{}( 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.