[erlang-questions] value of spawned function

Zvi <>
Fri Sep 19 16:06:39 CEST 2008


I trying to implement some Fork-Join constructs in Erlang using links or
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




-define(N, erlang:system_info(schedulers) ).

test_monitor() ->
	% fork
	PidRefs = [spawn_monitor(
			fun() -> io:format("pid: ~w~n",[self()]) end) ||
	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) ||
	io:format("Pids: ~w~n", [Pids]),
	% join
	[receive {'EXIT',Pid,_}->ok end || Pid<-Pids ].

if there is some better ways to implement fork join please let me know.

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.

More information about the erlang-questions mailing list