> On UNIX it would be better if it sent Hugs a signal when stack memory start
> running out; does anybody out there know of such a UNIX command? 

That'd be hard to deal with because the signal could happen on any
stack write - the machine might be in an inconsistent state.
(Potentially a problem for catching ctrl-C too.)

> and it says (p 100) UNIX systems have
> a system call sbrk() which adjusts the demarkation line between the stack
> and heap.

sbrk is used to allocate memory (typically by malloc).  All it really
tells you is the maximum heap address currently allocated.  It doesn't
tell you what the maximum value it could reach is and there's no
guarantee that this value is anywhere close to the stack limit.


However, a little asking around suggested something which might work:

1) Use getrlimit(RLIMIT_STACK, ...) to find out the maximum stack size.

2) Estimate actual stack size when Hugs starts up.  Let's guess it's
   8kbytes (or whatever) and lets allow a bit of slop space (8k again?)
   at the other end of the stack so we don't have to check the stack on
   every function call.

   Now we can calculate the maximum/minimum stack address (depending
   on which direction the stack grows): rlimit_stack - 16kbytes

3) Insert a stack check at the start of "eval" (is that enough?).
   If it triggers, throw an exception that the programmer
   can catch in the IO monad.  (See code for throwing pattern match 
   exceptions for comparision.)

--
Alastair Reid


Reply via email to