[erlang-questions] Question regarding problems in Joe's book

Zac Brown zac@REDACTED
Sat Jul 28 13:52:33 CEST 2007

Thanks for the responses guys. I guess I felt almost thrown into the wild 
when I saw that there were problems at the end. I actually figured out the
start(AnAtom, Fun) one, but the ring problem I've made some head way in
but I'm getting stuck with it. I'll post what I have so far and see if
there are any comments.

-export([start/0, submit/2, loop/0]).

start() ->
    spawn(fun loop/0).

submit(Pid, What) ->
    rpc(Pid, What).

loop() ->
	{data, Msg, PidList, Curr, Lim} ->
	    case Curr =< Lim of
		true -> [H|T] = PidList,
			rpc(H, {data, Msg, T++H, Curr+1, Lim});
		false -> Msg
	_ -> 

rpc(Pid, Request) ->
    Pid ! {self(), Request},
	Response ->

On Sat, 28 Jul 2007 02:07:12 -0400, Toby DiPasquale wrote:

> On 7/27/07, Mike Berrow <mberrow1@REDACTED> wrote:
>> > .....  but I wonder if anyone knows if there are answers posted
>> > for the problems at the end of section 8? I've been struggling with
>> > working out these problems and am looking to learn from an example.
>> I wondered the same thing. The first problem seems simple, but I am not
>> sure how to prove that it works when "two  parallel processes simultaneously evaluate start/2"
> I believe the answer Joe was looking for was to have a separate
> process that the first n processes send messages to in order to enact
> start(AnAtom, Fun). This guarantees that whichever is first gets the
> success message and those coming afterwards receive the failure
> message in response. This relies on Erlang's message passing
> concurrency to provide a sequencing of events in a parallel
> environment, rather than using shared state.
> In essence, I think its a clever question to make sure you were paying
> the proper attention to the preceding chapter's material ;-) Joe can,
> of course, embellish or correct me if I'm wrong. Joe?

More information about the erlang-questions mailing list