source: tests/coroutine/runningTotal.cfa @ 107b01a

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resnenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since 107b01a was 107b01a, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Several changes to the makefiles

  • change .c tests to .cfa
  • add require for libtool in configure
  • libtoolize to fix some warnings
  • Property mode set to 100644
File size: 1.2 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// runningTotal.c --
8//
9// Author           : Peter A. Buhr
10// Created On       : Wed Dec  6 08:05:27 2017
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Tue Dec 11 21:59:00 2018
13// Update Count     : 4
14//
15
16#include <fstream.hfa>
17#include <coroutine.hfa>
18
19coroutine RunTotal {                                                                    // input numbers and return running total
20        int input, total;                                                                       // communication
21};
22
23void ?{}( RunTotal & rntl ) { rntl.total = 0; }
24
25void update( RunTotal & rntl, int input ) with( rntl ) { // helper
26        total += input;                                                                         // remember between activations
27        suspend();                                                                                      // inactivate on stack
28}
29
30void main( RunTotal & rntl ) with( rntl ) {
31        for () {
32                update( rntl, input );
33        } // for
34}
35
36int add( RunTotal & rntl, int input ) {
37        rntl.input = input;                                                                     // pass input to coroutine
38        resume( rntl );
39        return rntl.total;                                                                      // return total from coroutine
40}
41int main() {
42        RunTotal rntl;
43        for ( i; 10 ) {
44                sout | i | add( rntl, i );
45        } // for
46}
47
48// Local Variables: //
49// tab-width: 4 //
50// compile-command: "cfa runningTotal.c" //
51// End: //
Note: See TracBrowser for help on using the repository browser.