process spec consumer() { trans void put(int) } process spec producer(process consumer);
process body consumer() { int c; for(;;) { accept put(a) c = a; if ( c == EOF ) break; putchar( islower(c)?toupper(c):c ); } } process body producer(process cons) { int c; do { cons.put( c = getchar() ); } while ( c != EOF ); }
void main() { create producer( create consumer() ); }
process spec diskDriver() { trans int request( int op, long blkaddr, char* buf ); trans int wait(int ticket); trans void done(); }; class disk { process diskDriver dd; int nwaiting, nbadrag, tickets MAX_PENDING , ...; public: ... };
class bounded_buffer : actor { int buf[MAX]; int in, out; public: bounded_buffer() { in=0; out=0; } int get() { reply buf[out++]; out %= MAX; if (in == out) become( empty_buffer,in,out); else become( partial_buffer,in,out); } void put( int item ) { buf[in++] = item; in %= MAX; if (in == out ) become( full_buffer,in,out); else become( partial_buffer,in,out); } };
class empty_buffer:bounded_buffer { public: bounded_buffer::put; }; class full_buffer:bounded_buffer { public: bounded_buffer::get; }; class partial_buffer:bounded_buffer { public: bounded_buffer::put; bounded_buffer::get; };