[erlang-questions] Re: testing asynchronous code

Bernard Duggan bernie@REDACTED
Thu Apr 22 03:12:18 CEST 2010


Jay Nelson wrote:
> On Apr 21, 2010, at 3:38 PM, Matthew Sackman wrote:
>
>   
>> On Wed, Apr 21, 2010 at 12:09:09PM -0700, Jay Nelson wrote:
>>     
>>> 1) Make sure you cast before the Pid leaks out to any callers
>>>       
>> Why? Do you think that gives you any guarantee that that message will
>> arrive in the mailbox before a message sent from a different  
>> process? I
>> would be a little surprised if that's guaranteed.
>>     
>
> You're right, the cast call spawns a process with a single call to  
> erlang:send/2, but that process may not get a chance to run before  
> the initializing process makes a gen_server:call.
That's not my reading of the gen_server code at all.  The do_send()
function (which is what ultimately does the erlang:send() of the
message) /only/ spawns a new function if erlang:send() returns
'noconnect', and that will only happen (if my understanding is correct)
if the process in question resides on a currently unconnected node.  In
the case of the example code given, that's not going to be the case
since the gen_server was started by the same process doing the cast, and
therefore even if it was started on a remote node we must already be
connected to that node.

To address the earlier question that lead to this, my understanding is
that if you have the following message sending:

A -> B
A -> C
C -> B (dependant on message from A)

then the message from A to B /is/ guaranteed to arrive before the
message from C.  Feel free to correct me on that though.

Cheers,

Bernard



More information about the erlang-questions mailing list