[erlang-questions] gen_server cast question

Logan, Martin Martin.Logan@REDACTED
Wed Jan 31 18:59:06 CET 2007


Oops, as Ulf pointed out, for a single process message ordering is
guaranteed.  You should not rely on it for multiple processes.  

-----Original Message-----
From: erlang-questions-bounces@REDACTED
[mailto:erlang-questions-bounces@REDACTED] On Behalf Of Logan, Martin
Sent: Wednesday, January 31, 2007 10:21 AM
To: Ladislav Lenart; Erlang-Questions (E-mail)
Subject: Re: [erlang-questions] gen_server cast question



-----Original Message-----
From: erlang-questions-bounces@REDACTED
[mailto:erlang-questions-bounces@REDACTED] On Behalf Of Ladislav
Lenart
Sent: Wednesday, January 31, 2007 9:20 AM
To: Erlang-Questions (E-mail)
Subject: [erlang-questions] gen_server cast question

Hello,

I was browsing erlang (library) sources and found the
following in gen_server module:

do_send(Dest, Msg) ->
   case catch erlang:send(Dest, Msg, [noconnect]) of
     noconnect ->
       spawn(erlang, send, [Dest, Msg]);
     Other ->
       Other
   end.

do_send is called for example from gen_server:cast/2.
I know what the code above does, but don't understand
how the following can work:

   gen_server:cast(Ref, msg1),
   gen_server:cast(Ref, msg2),
   gen_server:cast(Ref, msg3)

Suppose that Ref points to a process which resides on
the node that is not yet connected to the current node.
When the first cast is evaluated, noconnect is returned
and new process is spawned that sends the message msg1
to Ref. If the second cast is also evaluated before the
connection to the node is established, second process
is spawned that sends the message msg2 to Ref.

I think that there is a possibility that Ref will not
receive messages msg1, msg2 and msg3 in expected order
because of the internal spawning.

------------

Message order is not guaranteed with asynchronous messaging in any case.
You should never rely on it.  Also, as an aside, it would be strange to
have a reference to a process for a node that is not connected, that
suggests poor design. 

_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED
http://www.erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED
http://www.erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list