Changes in src/tests/coroutine.c [83a071f9:ec95d11]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/coroutine.c
r83a071f9 rec95d11 1 // 1 // 2 2 // Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo 3 3 // 4 4 // The contents of this file are covered under the licence agreement in the 5 5 // file "LICENCE" distributed with Cforall. 6 // 7 // fibonacci.c -- 8 // 6 // 7 // fibonacci.c -- 8 // 9 9 // Author : Thierry Delisle 10 10 // Created On : Thu Jun 8 07:29:37 2017 … … 12 12 // Last Modified On : Thu Jun 8 07:37:12 2017 13 13 // Update Count : 5 14 // 14 // 15 15 16 16 #include <fstream> … … 21 21 }; 22 22 23 void ?{}( Fibonacci &this ) {24 this .fn = 0;23 void ?{}( Fibonacci * this ) { 24 this->fn = 0; 25 25 } 26 26 27 void main( Fibonacci &this ) {27 void main( Fibonacci * this ) { 28 28 int fn1, fn2; // retained between resumes 29 this .fn = 0; // case 030 fn1 = this .fn;29 this->fn = 0; // case 0 30 fn1 = this->fn; 31 31 suspend(); // return to last resume 32 32 33 this .fn = 1; // case 133 this->fn = 1; // case 1 34 34 fn2 = fn1; 35 fn1 = this .fn;35 fn1 = this->fn; 36 36 suspend(); // return to last resume 37 37 38 38 for ( ;; ) { // general case 39 this .fn = fn1 + fn2;39 this->fn = fn1 + fn2; 40 40 fn2 = fn1; 41 fn1 = this .fn;41 fn1 = this->fn; 42 42 suspend(); // return to last resume 43 43 } // for 44 44 } 45 45 46 int next( Fibonacci &this ) {46 int next( Fibonacci * this ) { 47 47 resume( this ); // transfer to last suspend 48 return this .fn;48 return this->fn; 49 49 } 50 50 … … 52 52 Fibonacci f1, f2; 53 53 for ( int i = 1; i <= 10; i += 1 ) { 54 sout | next( f1 ) | ' ' | next(f2 ) | endl;54 sout | next( &f1 ) | ' ' | next( &f2 ) | endl; 55 55 } // for 56 56 }
Note:
See TracChangeset
for help on using the changeset viewer.