<div dir="ltr">Exactly. Erlang processes manage their own stacks and reallocate and grow them as needed. This means that stacks can start out very small (like 2-4 k) and you can have millions of processes without running out of address space for stacks.</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><br> /Richard</div></div>
<br><div class="gmail_quote">2017-10-07 15:23 GMT+02:00 Leandro Ostera <span dir="ltr"><<a href="mailto:leandro@ostera.io" target="_blank">leandro@ostera.io</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">@Richard, so there's no static stack limit, but rather the stack grows dynamically and the evaluation will be RAM-bound?</div><div class="HOEnZb"><div class="h5"><br><div class="gmail_quote"><div dir="ltr">On Sat, Oct 7, 2017 at 3:04 PM Richard Carlsson <<a href="mailto:carlsson.richard@gmail.com" target="_blank">carlsson.richard@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Your small function has no way to terminate, and very quickly eats up your system RAM with its ever growing stack. The CPU load is not the problem.</div><div class="gmail_extra"></div><div class="gmail_extra"><br clear="all"><div><div class="m_-5705590084341743166m_-7951993066692592648gmail_signature" data-smartmail="gmail_signature"><br> /Richard</div></div></div><div class="gmail_extra">
<br><div class="gmail_quote">2017-10-07 14:14 GMT+02:00 Arun <span dir="ltr"><<a href="mailto:arunp@utl.in" target="_blank">arunp@utl.in</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<p>Hi Leandro,</p>
<p>Am aware about tail recursion in erlang, but here I am talking
about recursion which is not tail recursive. Here is the code
snippet;</p>
<p>start(N) -><br>
N*start(N-1).</p>
<p>Here the function is not tail recursive and it is in an infinite
loop. If run this function my system is getting hang. That why i
got the doubt why it is making my system to hang and how the
erlang scheduler will behave in this scenario.?<br>
</p>
Regards,<br>
Arun P.<br>
<p><br>
</p>
<div class="m_-5705590084341743166m_-7951993066692592648m_-8414256906637233397moz-cite-prefix">On Saturday 07 October 2017 04:07 PM,
Leandro Ostera wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">Hej Arun, hi.
<div><br>
</div>
<div>Depending on your recursion, you may or may not be building
up a stack that will at some point crash. I am unsure about
how C compilers typically deal with tail-recursion, but tail
call optimization is automatically performed in the Erlang VM
for you.</div>
<div><br>
</div>
<div>From the Learn You Some Erlang book chapter on Recursion (<a href="http://learnyousomeerlang.com/recursion" target="_blank">http://learnyousomeerlang.<wbr>com/recursion</a>):<br>
<br>
<p style="background:url("http://learnyousomeerlang.com/static/img/note-background.jpg") no-repeat;margin:0px 0px 1.4em;padding:15px 0px 0px 20px;border:0px;outline:0px;font-size:0.9em;vertical-align:baseline;font-family:verdana,arial,helvetica,sans;line-height:1.4em"><strong style="margin:0px;padding:0px;border:0px;outline:0px;font-size:14.4px;vertical-align:baseline;background:transparent">Note:</strong> tail
recursion as seen here is not making the memory grow because
when the virtual machine sees a function calling itself in a
tail position (the last expression to be evaluated in a
function), it eliminates the current stack frame. This is
called tail-call optimisation (TCO) and it is a special case
of a more general optimisation named <em style="margin:0px;padding:0px;border:0px;outline:0px;font-size:14.4px;vertical-align:baseline;background:transparent">Last
Call Optimisation</em> (LCO).</p>
<p style="background:url("http://learnyousomeerlang.com/static/img/note-background.jpg") no-repeat;margin:0px 0px 1.4em;padding:15px 0px 0px 20px;border:0px;outline:0px;font-size:0.9em;vertical-align:baseline;font-family:verdana,arial,helvetica,sans;line-height:1.4em">LCO
is done whenever the last expression to be evaluated in a
function body is another function call. When that happens,
as with TCO, the Erlang VM avoids storing the stack frame.
As such tail recursion is also possible between multiple
functions. As an example, the chain of functions <code style="margin:0px;padding:0px;border-width:0px 0px 1px;border-top-style:initial;border-right-style:initial;border-bottom-style:dotted;border-left-style:initial;border-top-color:initial;border-right-color:initial;border-bottom-color:rgb(170,221,153);border-left-color:initial;outline:0px;font-size:1.1em;vertical-align:baseline;background:rgb(238,255,204);color:rgb(85,85,85)">a()
-> b(). b() -> c(). c() -> a().</code> will
effectively create an infinite loop that won't go out of
memory as LCO avoids overflowing the stack. This principle,
combined with our use of accumulators is what makes tail
recursion useful.</p>
</div>
<div><br>
</div>
<div>Hope this helps!</div>
</div><div><div class="m_-5705590084341743166m_-7951993066692592648h5">
<br>
<div class="gmail_quote">
<div dir="ltr">On Sat, Oct 7, 2017 at 9:03 AM Arun <<a href="mailto:arunp@utl.in" target="_blank">arunp@utl.in</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
I tried to run normal recursion program from erlang shell, the
program<br>
runs infinitely and it is doing addition of numbers. But its
been<br>
observed that soon after starting the program entire PC is
getting hang.<br>
<br>
My doubt is that, why my PC is getting hang. ? , if something
is going<br>
wrong, the erlang vm should be able to handle it, like in C if
we run<br>
some recursion program infinity, it will crash by throwing
segmentation<br>
fault error.<br>
<br>
What will be happening in the VM if I run a normal recursion
program in<br>
erlang infinitely ?<br>
<br>
What will be the behavior of erlang scheduler in this scenario
?<br>
<br>
Can somebody please assist me on this issue.<br>
<br>
Thanks in advance<br>
Arun P.<br>
______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
</blockquote>
</div>
</div></div></blockquote>
<br>
</div>
<br>______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div></blockquote></div>
</div></div></blockquote></div><br></div>