- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/concurrency/examples/Fib2.cfa
r1e5d0f0c r600d7be 10 10 // Created On : Thu Apr 26 23:20:08 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 22 17:26:41201913 // Update Count : 2812 // Last Modified On : Sat May 18 08:55:59 2019 13 // Update Count : 36 14 14 // 15 15 … … 17 17 #include <coroutine.hfa> 18 18 19 coroutine Fibonacci { int fn1 ; };// used for communication19 coroutine Fibonacci { int fn1, fn; }; // used for communication 20 20 21 21 void 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 24 23 for () { 25 24 suspend(); // restart last resume … … 29 28 30 29 int ?()( Fibonacci & fib ) with( fib ) { // function call operator 31 resume( fib ); // restart last suspend 32 return fn1; 30 return resume( fib ).fn1; // restart last suspend 33 31 } 34 32 … … 36 34 Fibonacci f1, f2; 37 35 for ( 10 ) { // print N Fibonacci values 38 sout | f1() | f2();36 sout | resume( f1 ).fn | resume( f2 ).fn; 39 37 } // for 40 38 } … … 42 40 // Local Variables: // 43 41 // tab-width: 4 // 44 // compile-command: "cfa fibonacci_1.cfa" //42 // compile-command: "cfa Fib2.cfa" // 45 43 // End: //
Note: See TracChangeset
for help on using the changeset viewer.