export process.h use stdlib.h # for NULL use sched.h # for start() # rendezvous system, which is the basis of inter-process channels struct rendezvous process *waiting rendezvous_init(rendezvous *r) r->waiting = NULL # here are the general rendezvous methods: # meet - if the partner is here, returns 0, # otherwise we wait for the partner to arrive, returns 1, # (caller must then yield) int meet(rendezvous *r, process *p) int must_wait = !r->waiting if must_wait r->waiting = p return must_wait # pass - give control to the partner # (this works whether or not they are here already) pass(rendezvous *r, process *p) if r->waiting start(r->waiting) r->waiting = p # part - finish the rendezvous # (this assumes they are here) part(rendezvous *r) start(r->waiting) r->waiting = NULL # peer - get the partner's process pointer # or NULL if they are not here process *peer(rendezvous *r) return r->waiting # here - check if the partner is here int here(rendezvous *r) return peer(r) != NULL