[erlang-questions] [LONG] How to make synchronous message passing

Adam Lindberg <>
Wed Oct 3 09:31:53 CEST 2007


What you are doing by using a synchronous sending mechanism as described
above AND letting both P and Q send requests to each other is effectively
implementing dead lock. Because messages will cross, sooner or later, and if
both P and Q can send requests to each other and these requests cross in
between you have a dead lock. You should consider what you really want to
achieve with synchronous message passing (or rather synchronous requests,
there are no such thing as synchronous message passing, it is one way only).

Synchronous requests can be desirable in certain situations, but almost
never in a P <-> Q relation. Then you would also need atomic synchronous
message requests. That could maybe be achieved but very unlikely what you
really want.

Cheers!
Adam

On 10/3/07, ZeD <> wrote:
>
> Richard Carlsson wrote:
>
> >> synchro(P, {do, Q, {ask, P}}).
> > It seems that you are not talking about normal synchronous
> communication,
> > but rather a form of nested request/reply. In synchronous message
> passing,
> > if P is waiting for a reply from Q then he is by definition blocked and
> > cannot answer the query from Q. Your implementation in synchro2 is
> > correct, but synchronous communication is not what you need for this
> > problem. You have to rethink what f does.
>
> mmm
>
> maybe I made a wrong example, or maybe you are right (effectively using
> asinchronous communications I can have a reply)... let me change the
> question:
>
> if a process P want to make a synchronous call to Q, then it send a
> message
> and waits for a reply.
>
> What's appened when another process, R (just for make and example) send a
> message to P 'before' the Q reply?
> In particular, what if Q first send another message to P, then waits for
> the
> reply, and only after all this, send the reply to the original message to
> P?
>
> Oh, and just to know, let's say P was described by the function f(), which
> have a receive; now P want to talk to Q, then now the behavior of P is
> described by synchro2(), wich also have a receive. Let's say P finally had
> a reply, so the control came back to f(). What append to messages not
> matched by synchro2()? they became automatically "receveived" by f()? They
> get lost?
>
> --
> Under construction
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071003/f09ae79f/attachment.html>


More information about the erlang-questions mailing list