# this version uses the "process" structure, # and a simple scheduler use stdio.h struct process typedef int (*process_func)(process *p) struct process process_func f int pc void *data int count_to_three(process *p) switch p->pc 0 printf("1\n") return 1 1 printf("2\n") return 2 2 printf("3\n") return 3 3 . return -1 struct count_to_n_data int n int c int count_to_n(process *p) count_to_n_data *d = (count_to_n_data *)p->data switch p->pc 0 d->c = 1 while d->c <= d->n printf("%d\n", d->c) ++ (d->c) return 1 1 . return -1 # will have to consider how to implement "child" or "sub-" processes using namespace std use deque int main() process c3 = { count_to_three, 0 } while c3.pc != -1 c3.pc = (*c3.f)(&c3) count_to_n_data d1, d2 process cn1 = { count_to_n, 0, &d1 } process cn2 = { count_to_n, 0, &d2 } d1.n = 10 d2.n = 15 deque q q.push_back(&cn1) q.push_back(&cn2) while !q.empty() process *p = q.front() q.pop_front() int pc = (*p->f)(p) if pc != -1 p->pc = pc q.push_back(p) return 0