source: tests/coroutine/pingpong.cfa @ c565d68

Last change on this file since c565d68 was 363b48f, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

change to reference, formatting

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[73abe95]1//
[9bae71f]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.
[73abe95]6//
7// pingpong.c --
8//
[9bae71f]9// Author           : Peter A. Buhr
10// Created On       : Wed Sep 20 11:55:23 2017
11// Last Modified By : Peter A. Buhr
[363b48f]12// Last Modified On : Tue Mar 26 17:54:14 2019
13// Update Count     : 35
[73abe95]14//
[9bae71f]15
[73abe95]16#include <coroutine.hfa>
17#include <fstream.hfa>
[9bae71f]18
19coroutine PingPong {
20        const char * name;
21        /* const */ unsigned int N;
[363b48f]22        PingPong & part;
[9bae71f]23};
24
25void ?{}( PingPong & this, const char * name, unsigned int N, PingPong & part ) {
[363b48f]26        this.[name, N] = [name, N];  &this.part = &part;
[9bae71f]27}
28void ?{}( PingPong & this, const char * name, unsigned int N ) {
[363b48f]29        this{ name, N, *0p };                                                           // call first constructor
[9bae71f]30}
31void cycle( PingPong & pingpong ) {
32        resume( pingpong );
33}
34void partner( PingPong & this, PingPong & part ) {
[363b48f]35        &this.part = &part;
[9bae71f]36        resume( this );
37}
[363b48f]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 );
[9bae71f]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 //
[f8cd310]52// compile-command: "cfa pingpong.cfa" //
[9bae71f]53// End: //
Note: See TracBrowser for help on using the repository browser.