Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/concurrency/examples/Fib2.cfa

    r1e5d0f0c r600d7be  
    1010// Created On       : Thu Apr 26 23:20:08 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 22 17:26:41 2019
    13 // Update Count     : 28
     12// Last Modified On : Sat May 18 08:55:59 2019
     13// Update Count     : 36
    1414//
    1515
     
    1717#include <coroutine.hfa>
    1818
    19 coroutine Fibonacci { int fn1; };                                               // used for communication
     19coroutine Fibonacci { int fn1, fn; };                                   // used for communication
    2020
    2121void main( Fibonacci & fib ) with( fib ) {                              // called on first resume
    22         int fn;
    23         [fn1, fn] = [0, 1];                                                                     // precompute first two states
     22        [fn1, fn] = [1, 0];                                                                     // precompute first two states
    2423        for () {
    2524                suspend();                                                                              // restart last resume
     
    2928
    3029int ?()( Fibonacci & fib ) with( fib ) {                                // function call operator
    31         resume( fib );                                                                          // restart last suspend
    32         return fn1;
     30        return resume( fib ).fn1;                                                       // restart last suspend
    3331}
    3432
     
    3634        Fibonacci f1, f2;
    3735        for ( 10 ) {                                                                            // print N Fibonacci values
    38                 sout | f1() | f2();
     36                sout | resume( f1 ).fn | resume( f2 ).fn;
    3937        } // for
    4038}
     
    4240// Local Variables: //
    4341// tab-width: 4 //
    44 // compile-command: "cfa fibonacci_1.cfa" //
     42// compile-command: "cfa Fib2.cfa" //
    4543// End: //
Note: See TracChangeset for help on using the changeset viewer.