Mario Charest postmaster@127.0.0.1 wrote:
David, in my last post I wanted to give a reason why stack cannot grow
dynamicaly and I couldn’t. I couldn’t find comfort in your explanation.
A philosophy of resiliency and process-limited resource growth.
Consider a program that has a bug in a recursive routine that recurses
forever… if stack grew dynamically, this would absorb ALL the free
memory on the system [for most systems] and quite possibly cause lots
of other things to fail when they couldn’t allocate memory. With a
limitted, fixed maximum, stack depth, the error will be limitted in
to that process. (Whereas, in a virtual memory system, the extra
allocated, but not currently in-use stack will be swapped/paged out
and not cause allocation failures elsewhere.)
You can’t have both pure dynamic stack growth, and the ability to detect
and handle (crash on) stack overflow.
Also, what happens when you have a multithreaded process – where do
you put the stacks for each thread. I don’t know how Linux lays out
the address space of the process, but we put the thread stack(s) in
the same address space as the rest of the process, and I expect they
probably have to as well. {I know trad Unix from way back, the address
space would be laid out with essentially code and data at bottom, heap
growing up from top of data, stack at top of address space, growing down
towards heap. In that model, where do you put multiple thread stacks?}
If you don’t have a boundary on the stack for the main thread, how do
you detect when it grows over into the stack for your next thread?
Now, maybe you could special-case the single threaded vs multi-threaded
programs… but even so, I don’t like it.
When working for a limitted-resource system, having hard boundaries,
that can be configured, is generally a better, more robust, way to
go.
Does that help?
(Of course, this is post-hoc justification, I wasn’t involved in the
actual design discussions where these decisions were made.)
-David
QNX Training Services
http://www.qnx.com/services/training/
Please followup in this newsgroup if you have further questions.