source: tests/coroutine/suspend_then.cfa @ 5b11c25

arm-ehcleanup-dtorsjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-expr
Last change on this file since 5b11c25 was 5b11c25, checked in by Thierry Delisle <tdelisle@…>, 2 years ago

Added new suspen_then function which runs a callback in the middle of susending

  • Property mode set to 100644
File size: 1.3 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2019 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// suspend_then.cfa --
8//
9// Author           : Peter A. Buhr
10// Created On       : Mon Apr 29 12:01:35 2019
11// Last Modified By :
12// Last Modified On :
13// Update Count     :
14//
15
16#include <fstream.hfa>
17#include <coroutine.hfa>
18
19void then() {
20        sout | "Then!";
21}
22
23coroutine Fibonacci { int fn; };                                                // used for communication
24
25void main( Fibonacci & fib ) with( fib ) {                              // called on first resume
26        int fn1, fn2;                                                           // retained between resumes
27        fn = 0;  fn1 = fn;                                                      // 1st case
28        suspend_then(then);                                                     // restart last resume
29        fn = 1;  fn2 = fn1;  fn1 = fn;                                  // 2nd case
30        suspend_then(then);                                                     // restart last resume
31        for () {
32                fn = fn1 + fn2;  fn2 = fn1;  fn1 = fn;                  // general case
33                suspend_then(then);                                             // restart last resume
34        } // for
35}
36
37int next( Fibonacci & fib ) with( fib ) {
38        resume( fib );                                                          // restart last suspend
39        return fn;
40}
41
42int main() {
43        Fibonacci f1, f2;
44        for ( 10 ) {                                                            // print N Fibonacci values
45                sout | next( f1 ) | next( f2 );
46        } // for
47}
48
49// Local Variables: //
50// tab-width: 4 //
51// compile-command: "cfa runningTotal.cfa" //
52// End: //
Note: See TracBrowser for help on using the repository browser.