Erlang Mailing Lists

Author Message

<  Erlang questions mailing list  ~  spawn_link(N,M,F,A)

pearcs at rpi.edu
Posted: Thu Dec 10, 1998 8:26 am Reply with quote
Guest
Ok, this might be a rather "stupid" question, but here goes:

I've written a simple client/server counter module based on the stuff from the
book. I've got two different erl JAM vm's running, one named "a_at_spearce", the
other "nt_at_spearce" using -sname for both. nt_at_spearce cannot find my counter
module due to the fact that its not in the current directory. a_at_spearce has it
loaded already from the shell ("c(counter).").

When i do this from a third shell:

spearce% erl_call -e -sname a_at_spearce
P=spawn_link('nt_at_spearce',erlang,apply,[counter,inc,[list_to_pid("<0.43.0>")]]),
receive
Any -> {P,Any}
end.
^D

the erl_call hangs with no output, and nothing is logged to either process.
Shouldn't i be getting an {'EXIT',{undef,{counter,inc,[<0.43.0>]}} message sent
to the thread handling the erl_call? Or am i looking at this the wrong way?

Just seemed rather strange with spawn about how certain errors are handled and
seem to deadlock a process....

(btw, nothing else is deadlocked, just this one erl_call.)

TIA.

--
Shawn.

(The above are the rantings of a body without a mind.)



Post generated using Mail2Forum (http://m2f.sourceforge.net)
magnus at erix.ericsson.s
Posted: Thu Dec 10, 1998 9:47 am Reply with quote
Guest
Shawn Pearce <pearcs_at_rpi.edu> wrote:
> Ok, this might be a rather "stupid" question, but here goes:

All questions are good ;-)

>
>
> the erl_call hangs with no output, and nothing is logged to either process.
> Shouldn't i be getting an {'EXIT',{undef,{counter,inc,[<0.43.0>]}} message
> sent to the thread handling the erl_call?

Yes, you should have got that.
If you run the same shell sequence in an erl shell you will receive just that
(rather your process will terminate unless you trap exit signals).

> Or am i looking at this the wrong way?

No, you have actually found a bug.
In the rpc:reply/5 (which is evaluated due to the erl_call stuff)
we do catch apply(M,F,A) but then F = spawn_link the apply call succeeds and
this function does not trap exit. Thus this process terminates and the
"gen_server:reply(To,{badrpc, {'EXIT', R}});" call is not evaluated =>
erl_call hangs.

The function looks like:
reply(To,Mod,Fun,Args,Gleader) ->
set_group_leader(Gleader),
case catch apply(Mod,Fun,Args) of
{'EXIT', R} ->
gen_server:reply(To,{badrpc, {'EXIT', R}});
Other ->
gen_server:reply(To,Other)
end.

Thanks !

/Magnus



Post generated using Mail2Forum (http://m2f.sourceforge.net)
joe at erix.ericsson.se
Posted: Thu Dec 10, 1998 9:52 am Reply with quote
Guest
> Ok, this might be a rather "stupid" question, but here goes:

There are no stupid questions - only bad replies

>
> I've written a simple client/server counter module based on the stuff from the
> book. I've got two different erl JAM vm's running, one named "a_at_spearce", the
> other "nt_at_spearce" using -sname for both. nt_at_spearce cannot find my counter
> module due to the fact that its not in the current directory. a_at_spearce has it
> loaded already from the shell ("c(counter).").
>
> When i do this from a third shell:
>
> spearce% erl_call -e -sname a_at_spearce
> P=spawn_link('nt_at_spearce',erlang,apply,[counter,inc,[list_to_pid("<0.43.0>")]]),
> receive
> Any -> {P,Any}
> end.
> ^D
>

Just I quick thought list_to_pid("<0.43.0>") is *very* error
prone. (list_to_pid is a stupid BIF that should be assigned to the "bad
ideas" dustbin.) It will *probably* work if you run on the same node and
have luch otherwise not.

pid_to_list(Pid) takes a Pid and produces an external printed
representation of the the Pid. This is mainly intended for debugging
the inverse operation whould probably be disallowed.

Much better to register the name of the Pid and use
whereis to find out where it is (or some variation of this)

/Joe

> the erl_call hangs with no output, and nothing is logged to either process.
> Shouldn't i be getting an {'EXIT',{undef,{counter,inc,[<0.43.0>]}} message sent
> to the thread handling the erl_call? Or am i looking at this the wrong way?
>
> Just seemed rather strange with spawn about how certain errors are handled and
> seem to deadlock a process....
>
> (btw, nothing else is deadlocked, just this one erl_call.)
>
> TIA.
>
> --
> Shawn.
>
> (The above are the rantings of a body without a mind.)
>



Post generated using Mail2Forum (http://m2f.sourceforge.net)
magnus at erix.ericsson.s
Posted: Thu Dec 10, 1998 10:34 am Reply with quote
Guest
Magnus Fr|berg <magnus_at_erix.ericsson.se> wrote:
>
> No, you have actually found a bug.
> In the rpc:reply/5 (which is evaluated due to the erl_call stuff)
> we do catch apply(M,F,A) but then F = spawn_link the apply call succeeds and
> this function does not trap exit.

Uhum, F is not spawn_link. 'erl_all -e' is equivalent to
rpc:call(Node, lib, eval_str, [#Bin]) (where the #Bin binary contains your
input to the erl_call shell).

But the result is almost the same, the rpc:reply process does not trap exit,
but the catch apply(M,F,A) does *not* succeed (the process crashes before
due to an exit signal) and the gen_server:reply is never evaluated.

Thus, if you first evaluates a process_flag(trap_exit, true) you will receive:

napoleon 39> erl_call -e -sname a
process_flag(trap_exit, true),
P=spawn_link(b_at_napoleon, erlang,apply,[counter,inc,[list_to_pid("<0.43.0>")]]),
receive
Any -> {P,Any}
end.
^D
{ok,{<b_at_napoleon.60.0>,{'EXIT',<b_at_napoleon.60.0>,{undef,{counter,inc,[<a_at_napole
on.43.0>]}}}}}
napoleon 40>

/Magnus





Post generated using Mail2Forum (http://m2f.sourceforge.net)

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum