On Apr 9 2011, Magnus Fromreide wrote:
There is actually a much better approach, which was done in Algol 68
and seems now to be done only in Ada. As far as the compiler
implementation goes, it is a trivial variation on what you have done,
but there is a little more work in the run-time system.
That is to use primary and secondary stacks. ...
How does your secondary stack interact with threads? Do it force the use
of more memory per thread?
No, there is no difference. You need a pair of stacks per thread, rather
than one, but that's all.
On Apr 9 2011, Eric Botcazou wrote:
Obviously this depends on the compiler. GNAT allocates all local arrays
on the primary stack for example.
Interesting. I was relying on what (several) other people had told me.
But, yes, it's entirely compiler-dependent, and can be done or not in
any conventional 3GL language.
You need a single secondary stack pointer (and preferably limit, for
checking), which can be global variables. If a procedure uses the
secondary stack, it needs to restore it on leaving, or when leaving
a scope including an allocation - but you have already implemented
that!
Not exactly, managing a secondary stack isn't supported in the GENERIC
IL, you need to do it explicitly by inserting calls to the runtime at
relevant points. As a consequence, this isn't an efficient mechanism,
hence the restricted use.
Naturally, every mechanism can be done badly, and I agree that it is
very common for the best solution to be infeasible because of some other
aspect. You still get the cache benefits with a pair of calls, but they
do add a lot of overhead.
Regards,
Nick Maclaren.