[erlang-questions] value of spawned function
Gleb Peregud
gleber.p@REDACTED
Fri Sep 19 17:43:12 CEST 2008
You may try to use erlang:exit/1 to make 'EXIT'/'DOWN' message
"return" something instead of 'normal'.
Take a look at plists: http://code.google.com/p/plists/ - it
implements quite a lot of parallel list operations, which may be what
you are looking for :)
On Fri, Sep 19, 2008 at 4:06 PM, Zvi <exta7@REDACTED> wrote:
>
> Hi,
>
> I trying to implement some Fork-Join constructs in Erlang using links or
> monitors.
> I do not understand why when process finished executing function normally,
> it's (function's) return value isn't put into 'EXIT' or 'DOWN' messages?
> I.e. instead of atom 'normal' return {normal, ResultOfFun} or something
> similar.
>
> {'EXIT',Pid,normal}
>
> {'DOWN',Ref,process,Pid,normal}
>
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> -module(fj).
> -compile(export_all).
>
> -define(N, erlang:system_info(schedulers) ).
>
> test_monitor() ->
> % fork
> PidRefs = [spawn_monitor(
> fun() -> io:format("pid: ~w~n",[self()]) end) ||
> _<-lists:seq(1,?N)],
> io:format("PidRefs: ~w~n", [PidRefs]),
> % join
> [receive {'DOWN',Ref,process,Pid,_}->ok end || {Pid,Ref}<-PidRefs ].
>
> test_link() ->
> % fork
> process_flag(trap_exit, true),
> Pids = [spawn_link(
> fun() -> io:format("pid: ~w~n",[self()]) end) ||
> _<-lists:seq(1,?N)],
> io:format("Pids: ~w~n", [Pids]),
> % join
> [receive {'EXIT',Pid,_}->ok end || Pid<-Pids ].
>
> P.S.
> if there is some better ways to implement fork join please let me know.
>
> Zvi
> --
> View this message in context: http://www.nabble.com/value-of-spawned-function-tp19573059p19573059.html
> Sent from the Erlang Questions mailing list archive at Nabble.com.
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
--
Gleb Peregud
http://gleber.pl/
Every minute is to be grasped.
Time waits for nobody.
-- Inscription on a Zen Gong
More information about the erlang-questions
mailing list