[erlang-questions] gen_server:cast/2 reordering

Kenneth Lundin kenneth.lundin@REDACTED
Mon Nov 10 21:35:07 CET 2008

On Mon, Nov 10, 2008 at 4:03 PM, Ben Hood <0x6e6562@REDACTED> wrote:
> Hi all,
> I am interested in the reordering semantics of gen_server:cast/2.
> I have just been looking at the source it and by default it uses the
> noconnect flag.
> There was this thread about it almost 2 years ago:
> http://www.erlang.org/pipermail/erlang-questions/2007-January/025047.html
> But this last question didn't seem to get answered.
> My question is: if I want to guarantee the message order from one
> particular process to another process, do I have to avoid using the
> noconnect flag, e.g.
> Dest ! { '$gen_cast, Msg}
If you send to a process on the same E-node the ordering will be guaranteed even
if you use gen_server:cast/2 since the noconnect flag will have no
effect on local calls.

If calling gen_server:cast/2 with a message to another E-node the
ordering will not be
guaranteed because of the spawn which happens if there is no existing
connection to the addressed E-node.

You can use
Dest ! { '$gen_cast, Msg}
to get a guaranteed order
On the other hand your process will be blocked until a connection with
the other E-node
is established or the connection attempt has failed.

/Kenneth Erlang/OTP Ericsson

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

More information about the erlang-questions mailing list