source: tests/coroutine/pingpong.cfa @ 363b48f

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

change to reference, formatting

  • Property mode set to 100644
File size: 1.3 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// pingpong.c --
8//
9// Author           : Peter A. Buhr
10// Created On       : Wed Sep 20 11:55:23 2017
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Tue Mar 26 17:54:14 2019
13// Update Count     : 35
14//
15
16#include <coroutine.hfa>
17#include <fstream.hfa>
18
19coroutine PingPong {
20        const char * name;
21        /* const */ unsigned int N;
22        PingPong & part;
23};
24
25void ?{}( PingPong & this, const char * name, unsigned int N, PingPong & part ) {
26        this.[name, N] = [name, N];  &this.part = &part;
27}
28void ?{}( PingPong & this, const char * name, unsigned int N ) {
29        this{ name, N, *0p };                                                           // call first constructor
30}
31void cycle( PingPong & pingpong ) {
32        resume( pingpong );
33}
34void partner( PingPong & this, PingPong & part ) {
35        &this.part = &part;
36        resume( this );
37}
38void main( PingPong & pingpong ) with(pingpong) {               // ping's starter ::main, pong's starter ping
39        for ( N ) {                                                                                     // N ping-pongs
40                sout | name;
41                cycle( part );
42        } // for
43}
44int main() {
45        enum { N = 20 };
46        PingPong ping = { "ping", N }, pong = { "pong", N, ping };
47        partner( ping, pong );
48}
49
50// Local Variables: //
51// tab-width: 4 //
52// compile-command: "cfa pingpong.cfa" //
53// End: //
Note: See TracBrowser for help on using the repository browser.