source: doc/papers/concurrency/examples/Pingpong.cfa@ 300fbee

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 300fbee 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
RevLine 
[17c6c1c3]1#include <coroutine.hfa>
2#include <fstream.hfa>
3
4coroutine PingPong {
5 const char * name;
[1e5d0f0c]6 unsigned int N;
7 PingPong & part;
[17c6c1c3]8};
9
10void ?{}( PingPong & this, const char * name, unsigned int N, PingPong & part ) {
[1e5d0f0c]11 this.[name, N] = [name, N]; &this.part = &part;
[17c6c1c3]12}
13void ?{}( PingPong & this, const char * name, unsigned int N ) {
[1e5d0f0c]14 this{ name, N, *0p }; // call first constructor
[17c6c1c3]15}
16void cycle( PingPong & pingpong ) {
17 resume( pingpong );
18}
19void partner( PingPong & this, PingPong & part ) {
[1e5d0f0c]20 &this.part = &part;
[17c6c1c3]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 );
[17c6c1c3]27 } // for
28}
29int main() {
[1e5d0f0c]30 enum { N = 5 };
[17c6c1c3]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" //
[17c6c1c3]38// End: //
Note: See TracBrowser for help on using the repository browser.