# separate components into different files use stdio.h use sched use channel main() sched_init() ch(int) ch ch_init(ch) 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 #coro_init(count_to_three, ch(int) *out) count_to_three_init(count_to_three *d, ch(int) *out) process_init(&d->p, count_to_three_f) s(out) = out coro(count_to_three) wr(out, 1) wr(out, 2) wr(out, 3) stop struct printer process p ch(int) *in printer_init(printer *d, ch(int) *in) process_init(&d->p, printer_f) s(in) = in coro(printer) repeat int v rd(in, v) printf("%d\n", v) stop struct count_to_n process p ch(int) *out int n int i count_to_n_init(count_to_n *d, ch(int) *out, int n) process_init(&d->p, count_to_n_f) s(out) = out s(n) = n coro(count_to_n) for s(i)=1; s(i)<=s(n); ++s(i) wr(out, s(i)) 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) s(n) = n coro(print_dots) while s(n) > 0 printf(".\n") -- s(n) yield stop channel(int)