summaryrefslogtreecommitdiff
path: root/rts/Threads.c
diff options
context:
space:
mode:
authorAustin Seipp <aseipp@pobox.com>2013-09-08 02:08:45 -0500
committerAustin Seipp <aseipp@pobox.com>2013-09-08 03:55:06 -0500
commitd85044f6b201eae0a9e453b89c0433608e0778f0 (patch)
tree2ef70aed38ac9ee9b0c7dc3f1cdf8a8e79091c11 /rts/Threads.c
parentc73d372bfebb5acee45e196d4e8694b656c7fd82 (diff)
downloadhaskell-d85044f6b201eae0a9e453b89c0433608e0778f0.tar.gz
Default to infinite stack size (#8189)
When servicing a stack overflows, only throw an exception to the given thread if the user explicitly set a max stack size, using +RTS -K. Otherwise just service it normally and grow the stack. In case we actually run out of *heap* (stack chuncks are allocated on the heap), then we need to bail by calling the stackOverflow() hook and exit immediately. Authored-by: Ben Gamari <bgamari.foss@gmail.com> Signed-off-by: Austin Seipp <aseipp@pobox.com>
Diffstat (limited to 'rts/Threads.c')
-rw-r--r--rts/Threads.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/rts/Threads.c b/rts/Threads.c
index 14fb7e872c..90d3dfd115 100644
--- a/rts/Threads.c
+++ b/rts/Threads.c
@@ -499,7 +499,8 @@ threadStackOverflow (Capability *cap, StgTSO *tso)
IF_DEBUG(sanity,checkTSO(tso));
- if (tso->tot_stack_size >= RtsFlags.GcFlags.maxStkSize
+ if ( (RtsFlags.GcFlags.maxStkSize > 0) // don't throw if we have infinite stack
+ && (tso->tot_stack_size >= RtsFlags.GcFlags.maxStkSize)
&& !(tso->flags & TSO_BLOCKEX)) {
// NB. never raise a StackOverflow exception if the thread is
// inside Control.Exceptino.block. It is impractical to protect
@@ -575,7 +576,12 @@ threadStackOverflow (Capability *cap, StgTSO *tso)
"allocating new stack chunk of size %d bytes",
chunk_size * sizeof(W_));
- new_stack = (StgStack*) allocate(cap, chunk_size);
+ new_stack = (StgStack*) allocateFail(cap, chunk_size);
+ if (new_stack == NULL) {
+ // We've really run out of memory in the heap, so die.
+ stackOverflow(tso);
+ stg_exit(EXIT_STACKOVERFLOW);
+ }
SET_HDR(new_stack, &stg_STACK_info, old_stack->header.prof.ccs);
TICK_ALLOC_STACK(chunk_size);