[erlang-questions] there is a blocking in the process evaluating the huge factorial
systemio systemio
systemio@REDACTED
Thu Jun 2 16:27:48 CEST 2011
Hi all,
My Erlang is (Erlang R13B03 (erts-5.7.4) [smp:2:2] [rq:2] [async-threads:0]).
WinXP SP1.
I've found the strange behavior when i spawn the process to evaluate the huge
factorial.
Here is the factorial module:
-module(test).
-compile(export_all).
fac(0) ->
1;
fac(N) ->
N * fac(N-1).
Here is the Erlang Shell code:
1> Fac = fun() -> test:fac(100000) end.
#Fun<erl_eval.20.67289768>
2> S1 = fun()-> spawn(Fac), timer:sleep(3000), io:format("Will I am", []),
spawn(Fac) end.
#Fun<erl_eval.20.67289768>
3> S2 = fun()-> spawn(Fac), io:format("Will I am", []), spawn(Fac) end.
#Fun<erl_eval.20.67289768>
4> S1().
Will I am<0.38.0>
5> S2().
Will I am<0.42.0>
In my PC the fun Fac evaluates about 11 sec.
If i start S1() i will see the message "Will I am" after 14 sec and it is
strange as i expect it after 3 seconds. After message appeares i type "i()."
and hit enter. This command is blocked and result appeares after 11 sec until
second process evaluates.
if i start S2() i will see the message "Will i am" immediately but i will not
be able to type anything in the shell and my typing will appear after 22 sec.
Also i've tested it with spawn(Node, ...) and the result is IAE same.
Are these behaviors valid or do i do smth wrong?
~
Alex
More information about the erlang-questions
mailing list