From whence do monitors come?

Matthew Sackman matthew@REDACTED
Fri Sep 10 15:07:58 CEST 2010


gen.erl has the following code in do_call:

	    catch erlang:send(Process, {Label, {self(), Mref}, Request},
		  [noconnect]),
	    receive
		{Mref, Reply} ->
		    erlang:demonitor(Mref, [flush]),
		    {ok, Reply};
		{'DOWN', Mref, _, _, noconnection} ->
		    exit({nodedown, Node});
		{'DOWN', Mref, _, _, Reason} ->
		    exit(Reason)

If the callee is something like a gen_server, and on handling that msg
returns a {stop, Reply, Reason, State} quple, there seems to be a race
between the reply and the monitor. Or more simply, say the callee does
something like:

receive {'$gen_call', From, _Msg} -> gen_server:reply(From, done) end.

There seems to be a race - what's stopping the DOWN from the monitor
overtaking the reply from the callee?

The only thing that I can think of is that the DOWN is considered to
come *from* the callee. Is that right?

Matthew


More information about the erlang-questions mailing list