In place of a lecture today, please watch two talks by Rob Pike: "Concurrency
is not Parallelism". with slides available here; (use your left and right arrow keys to navigate the slides)
and
Go concurrency patterns
with slides here.
The first 14 minutes or so of the first talk review discussions we've had in this class before -- Pike's perspective should complement things we've alread talked about. Then comes a very brief intro to Go's concurrency mechanisms. About 23 minutes in he talks about a load balancer design and implementation. He touts the value of having channels as first-class values.
Study questions for the first talk:
-
for the second load balancer example (the slide with title "Request definition", #46 in the URL), suppose you were writing it in Erlang instead of Go. What would be passed as part of the request messages instead of a channel?
- In the discussion of select (slide title "Select", #34) he talks about the default case that is
taken immediately if none of the other cases can be executed, like Erlang's
after 0
. How would you use the technique of the Channel example (slide 33) to implement a timeout option for select similar to that of Erlang's after
with a time value.
Study questions for the second talk. Note that the slides have a Run button that you can use to run the code on the slides.
- In what ways is communication in Go like communication in Erlang? In what ways is it like
communication in CML?
- On slide #36 what is the type of
timeout
. Why is the behavior on slide #36 different from that on slide #35 (beyond the comment that's already on the slide!)
- Suggest a plausible implementation of the time.After function used on slide #36.
- The Daisy-chain example (slide 39) is a bit like the rings that we created in Erlang, but the ring
exists only for as long as it takes to pass a single message around it. How could you make it support
passing an arbitrary number of messages?
- In CML (and in the synchronous communication assignment) the existence of Events as first-class
values lets the
select
operation be implemented as a normal function operating on a list
of Event values -- no special
syntax required. In Go, select is implemented using special syntax -- the select
statement
much as in Erlang communication is implemented using special syntax -- the receive
operation
and the !
operation. What advantages/disadvantages do you see with each approach?