ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since 4eaefd1 was
1427e90,
checked in by Thierry Delisle <tdelisle@…>, 6 years ago
|
Added coroutine name to pingpong program for better errors
|
-
Property mode set to
100644
|
File size:
1.3 KB
|
Rev | Line | |
---|
[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 |
---|
[200fcb3] | 12 | // Last Modified On : Tue Dec 11 21:58:06 2018 |
---|
| 13 | // Update Count : 29 |
---|
[73abe95] | 14 | // |
---|
[9bae71f] | 15 | |
---|
[73abe95] | 16 | #include <coroutine.hfa> |
---|
| 17 | #include <fstream.hfa> |
---|
[9bae71f] | 18 | |
---|
| 19 | coroutine PingPong { |
---|
| 20 | const char * name; |
---|
| 21 | /* const */ unsigned int N; |
---|
| 22 | PingPong * part; |
---|
| 23 | }; |
---|
| 24 | |
---|
| 25 | void ?{}( PingPong & this, const char * name, unsigned int N, PingPong & part ) { |
---|
[1427e90] | 26 | (this.__cor){name}; |
---|
[9bae71f] | 27 | this.name = name; |
---|
| 28 | this.N = N; |
---|
| 29 | this.part = ∂ |
---|
| 30 | } |
---|
| 31 | void ?{}( PingPong & this, const char * name, unsigned int N ) { |
---|
| 32 | this{ name, N, *(PingPong *)0 }; |
---|
| 33 | } |
---|
| 34 | void cycle( PingPong & pingpong ) { |
---|
| 35 | resume( pingpong ); |
---|
| 36 | } |
---|
| 37 | void partner( PingPong & this, PingPong & part ) { |
---|
| 38 | this.part = ∂ |
---|
| 39 | resume( this ); |
---|
| 40 | } |
---|
| 41 | void main( PingPong & pingpong ) { // ping's starter ::main, pong's starter ping |
---|
[ae4af81] | 42 | for ( pingpong.N ) { // N ping-pongs |
---|
[200fcb3] | 43 | sout | pingpong.name; |
---|
[9bae71f] | 44 | cycle( *pingpong.part ); |
---|
| 45 | } // for |
---|
| 46 | } |
---|
| 47 | int main() { |
---|
| 48 | enum { N = 20 }; |
---|
| 49 | PingPong ping = { "ping", N }, pong = { "pong", N, ping }; |
---|
| 50 | partner( ping, pong ); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | // Local Variables: // |
---|
| 54 | // tab-width: 4 // |
---|
| 55 | // compile-command: "cfa pingpong.c" // |
---|
| 56 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.