Last change
on this file since c4497e3 was
a573c22,
checked in by Peter A. Buhr <pabuhr@…>, 5 years ago
|
example programs updated for concurrency paper
|
-
Property mode set to
100644
|
File size:
541 bytes
|
Rev | Line | |
---|
[466fa01] | 1 | #include <stdio.h> |
---|
| 2 | |
---|
| 3 | typedef struct { |
---|
[a573c22] | 4 | int restart, fn1, fn; |
---|
[466fa01] | 5 | } Fib; |
---|
[a573c22] | 6 | #define FibCtor { 0, 1, 0 } |
---|
[466fa01] | 7 | |
---|
| 8 | Fib * comain( Fib * f ) { |
---|
[a573c22] | 9 | static void * states[] = {&&s0, &&s1}; |
---|
| 10 | goto *states[f->restart]; |
---|
| 11 | s0: f->restart = 1; |
---|
[466fa01] | 12 | for ( ;; ) { |
---|
| 13 | return f; |
---|
| 14 | s1:; int fn = f->fn + f->fn1; |
---|
| 15 | f->fn1 = f->fn; f->fn = fn; |
---|
| 16 | } |
---|
| 17 | } |
---|
| 18 | int main() { |
---|
| 19 | Fib f1 = FibCtor, f2 = FibCtor; |
---|
| 20 | for ( int i = 0; i < 10; i += 1 ) |
---|
| 21 | printf( "%d %d\n", comain( &f1 )->fn, comain( &f2 )->fn ); |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | // Local Variables: // |
---|
| 25 | // tab-width: 4 // |
---|
| 26 | // compile-command: "gcc-8 Fib3.c" // |
---|
| 27 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.