[erlang-questions] there is a blocking in the process evaluatingthe huge factorial

systemio systemio <>
Fri Jun 3 10:53:12 CEST 2011


but the same behavior if i make this below (io:format doesn't matter). Start S3() wait for a 3 seconds and try to type something. the typing will appear after factorial will be evaluated. BUT sometimes i can typing. It's very strange. (PS. i don't know if this answer will be posted right, because erlang-questions forum is strange for me, i didn't find any buttons like Reply or Answer, i've only made Reply All in my mail web tool.)

5> S3 = fun()-> spawn(Fac) end.
#Fun<erl_eval.20.67289768>
6> S3().
<0.46.0>
7>ughuihuihiuh

Thu, 2 Jun 2011 11:54:43 -0700 письмо от Mike Oxford <>:

As a guess;  io:format sends the message to the group leader for output.
If your group leader were to change based on the spawn() call, you may have your io:format message in the run queue behind the fac call.

More information may be found here... http://www.trapexit.org/forum/viewtopic.php?p=43855

Again, just a guess. :) 

G'luck!

-mox

On Thu, Jun 2, 2011 at 7:27 AM, systemio systemio <> wrote:
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
_______________________________________________
erlang-questions mailing list

http://erlang.org/mailman/listinfo/erlang-questions


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110603/aede8d06/attachment.html>


More information about the erlang-questions mailing list