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