Skip to content

Instantly share code, notes, and snippets.

@vito
Created July 29, 2010 00:02
Show Gist options
  • Save vito/496802 to your computer and use it in GitHub Desktop.
Save vito/496802 to your computer and use it in GitHub Desktop.
. |
| .
. |
| .
. |
| .
. |
| .
. |
| .
| .
volley finished
@done
-- starts a match of n volleys
volley: (n: Integer) = {
-- start up the ponger
proc = { notify |
pong: notify
} spawn-with: [self];
-- start up the pinger
{ ping: n ponger: proc } spawn
} do;
pong: notify = {
receive match: {
-- volley is done; finish
@finished -> {
" | ." write;
"volley finished" write;
notify ! @done
} do;
-- got a ping, send a pong
@(ping: pid) -> {
" . |" write;
pid ! @pong;
pong: notify -- loop
} do
}
} do;
ping: 0 ponger: pid = pid ! @finished;
ping: n ponger: pid = {
pid ! @(ping: self);
-- got a pong; send a ping
receive match: {
@pong -> {
"| . " write;
ping: (n - 1) ponger: pid
} do
}
} do;
-- start up the match, doing 5 volleys
volley: 5;
-- wait for the match to complete
receive print;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment