Changes in src/tests/coroutine.c [f802e46:83a071f9]
- File:
-
- 1 edited
-
src/tests/coroutine.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/tests/coroutine.c
rf802e46 r83a071f9 10 10 // Created On : Thu Jun 8 07:29:37 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Sep 17 21:38:15201713 // Update Count : 712 // Last Modified On : Thu Jun 8 07:37:12 2017 13 // Update Count : 5 14 14 // 15 15 … … 18 18 19 19 coroutine Fibonacci { 20 int fn; // used for communication20 int fn; // used for communication 21 21 }; 22 22 … … 26 26 27 27 void main( Fibonacci & this ) { 28 int fn1, fn2; // retained between resumes29 this.fn = 0; // case 028 int fn1, fn2; // retained between resumes 29 this.fn = 0; // case 0 30 30 fn1 = this.fn; 31 suspend(); // restartlast resume31 suspend(); // return to last resume 32 32 33 this.fn = 1; // case 1 34 fn2 = fn1; fn1 = this.fn; 35 suspend(); // restart last resume 33 this.fn = 1; // case 1 34 fn2 = fn1; 35 fn1 = this.fn; 36 suspend(); // return to last resume 36 37 37 for ( ;; ) { // general case38 for ( ;; ) { // general case 38 39 this.fn = fn1 + fn2; 39 fn2 = fn1; fn1 = this.fn; 40 suspend(); // restart last resume 40 fn2 = fn1; 41 fn1 = this.fn; 42 suspend(); // return to last resume 41 43 } // for 42 44 } 43 45 44 46 int next( Fibonacci & this ) { 45 resume( this ); // restartlast suspend47 resume( this ); // transfer to last suspend 46 48 return this.fn; 47 49 } … … 50 52 Fibonacci f1, f2; 51 53 for ( int i = 1; i <= 10; i += 1 ) { 52 sout | next( f1 ) | next( f2 ) | endl;54 sout | next( f1 ) | ' ' | next( f2 ) | endl; 53 55 } // for 54 56 }
Note:
See TracChangeset
for help on using the changeset viewer.