Andy Glew wrote:
On platforms where Fortran is commonly used, the stack limit isn't
that low. Low stack limits are e-vile.
-- greg
Hey, let's make a comp.arch topic!
How would you allocate stacks if you wanted, say, 1000 threads.
A megabyte apiece? A gigabyte apiece?
Contiguous stacks are a pain.
I disagree.
The potential amount of space a thread might use is a property
only of its specified starting routine.
For threads to operate reliably you need to ensure that their
worst case allocation is available (reserved but not allocated).
Unless you can prove that all your threads cannot use the
worst case at once, you must assume that it might happen.
Otherwise the application will randomly fail.
That means there is no advantage to dynamic stack chaining as
you must ensure that the heap contains sufficient space anyway,
and chaining becomes just a more expensive way to manage stacks.
I conclude therefore that the correct solution is to specify the
reserved linear stack size for each individual thread at create
and that means it is as an argument to the ThreadCreate function.
Note that this is NOT how Win32 works. As an optimization one could
maintain a pool of previously used stack ranges to save continuously
reserving and releasing the same sized memory sections.
As the stack grows down, each thread should track its low water mark,
and bounds check and commit new space efficiently, as a single system
request, only when below the mark. This is also not how Win32 works.
Eric