Main setup
- Define how processes step P \to Q
- New addition: each transition may have a label
- Labels model sending and receiving
- (A, n): send num n along channel A
- (\bar{A}, n): receive num n from channel A
- Other steps: no label (silent transitions)
Theory and Design of PL (CS 538)
April 20, 2020
Start early, especially if you haven’t tried writing concurrent code before
num = "0" | "1" | "2" | ...
var = "x" | "y" | "z" | ...
exp = num | var | exp "+" exp | exp "*" exp | ...
chn = "A" | "B" | "C" | ...
I
: input channel into programO
: output channel from programprc = "done" (* do nothing *)
| "make" chn "in" prc (* make new channel *)
| "send" exp "->" chn "then" prc (* send a message *)
| "recv" var "<-" chn "then" prc (* receive a message *)
| "[" exp "<" exp "]" prc (* run if guard true *)
| prc "+" prc (* run this or that *)
| prc "|" prc (* run in parallel *)
name = "P1" | "P2" | "P3" | ... (* names of processes *)
prc = ...
| name (* process could be a name *)
def = name "=" prc (* definition of processes *)
dolphin() ->
receive
do_a_flip ->
io:format("How about no?~n");
fish ->
io:format("So long and thanks for all the fish!~n");
_ ->
io:format("Heh, we're smarter than you humans.~n")
end.
main() ->
univ_pid = spawn(fun universal_server/0),
univ_pid ! {become, fun factorial_server/0},
univ_pid ! {self(), 50},
receive
Response -> Response
end.
/0
means zero arguments (Erlang dynamically typed)