# separate components into different files use stdio.h use sched use rendezvous main() sched_init() ch(int) ch rendezvous_init(&ch.r) count_to_three c3 count_to_three_init(&c3, &ch) printer pr printer_init(&pr, &ch) print_dots pd print_dots_init(&pd, 20) start(c3) start(pr) start(pd) run() count_to_n cn count_to_n_init(&cn, &ch, 15) start(cn) run() # we could do with Plan 9 cc's struct inheritance # my namespaces feature will be better, though! struct count_to_three process p ch(int) *out count_to_three_init(count_to_three *d, ch(int) *out) process_init(&d->p, count_to_three_f) d->out = out coro(count_to_three) meet(out) c(out) = 1 part(out) meet(out) c(out) = 2 part(out) meet(out) c(out) = 3 part(out) stop struct printer process p ch(int) *in printer_init(printer *d, ch(int) *in) process_init(&d->p, printer_f) d->in = in coro(printer) repeat pass(in) printf("%d\n", c(in)) stop struct count_to_n process p ch(int) *out int n count_to_n_init(count_to_n *d, ch(int) *out, int n) process_init(&d->p, count_to_n_f) d->out = out d->n = n coro(count_to_n) meet(out) c(out) = 1 part(out) while c(out) < s(n) meet(out) ++ c(out) part(out) stop # this one is an example of normal yielding struct print_dots process p int n print_dots_init(print_dots *d, int n) process_init(&d->p, print_dots_f) d->n = n coro(print_dots) while s(n) > 0 printf(".\n") -- s(n) yield stop channel(int)