[project @ 1999-04-27 10:59:29 by sewardj]
[ghc-hetmet.git] / ghc / rts / Schedule.c
index a0392f6..09aeb15 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Schedule.c,v 1.16 1999/03/16 13:20:16 simonm Exp $
+ * $Id: Schedule.c,v 1.20 1999/04/27 10:59:31 sewardj Exp $
  *
  * (c) The GHC Team, 1998-1999
  *
@@ -515,13 +515,19 @@ threadStackOverflow(StgTSO *tso)
   StgTSO *dest;
 
   if (tso->stack_size >= tso->max_stack_size) {
-    /* ToDo: just kill this thread? */
-#ifdef DEBUG
+#if 0
     /* If we're debugging, just print out the top of the stack */
     printStackChunk(tso->sp, stg_min(tso->stack+tso->stack_size, 
                                     tso->sp+64));
 #endif
-    stackOverflow(tso->max_stack_size);
+#ifdef INTERPRETER
+    fprintf(stderr, "fatal: stack overflow in Hugs; aborting\n" );
+    exit(1);
+#else
+    /* Send this thread the StackOverflow exception */
+    raiseAsync(tso, (StgClosure *)&stackOverflow_closure);
+#endif
+    return tso;
   }
 
   /* Try to double the current stack size.  If that takes us over the
@@ -557,9 +563,15 @@ threadStackOverflow(StgTSO *tso)
 
   /* Mark the old one as dead so we don't try to scavenge it during
    * garbage collection (the TSO will likely be on a mutables list in
-   * some generation, but it'll get collected soon enough).
+   * some generation, but it'll get collected soon enough).  It's
+   * important to set the sp and su values to just beyond the end of
+   * the stack, so we don't attempt to scavenge any part of the dead
+   * TSO's stack.
    */
   tso->whatNext = ThreadKilled;
+  tso->sp = (P_)&(tso->stack[tso->stack_size]);
+  tso->su = (StgUpdateFrame *)tso->sp;
+  tso->blocked_on = NULL;
   dest->mut_link = NULL;
 
   IF_DEBUG(sanity,checkTSO(tso));
@@ -634,9 +646,10 @@ unblockThread(StgTSO *tso)
          if (mvar->tail == tso) {
            mvar->tail = last_tso;
          }
-         break;
+         goto done;
        }
       }
+      barf("unblockThread (MVAR): TSO not found");
     }
 
   case BLACKHOLE_BQ:
@@ -648,17 +661,20 @@ unblockThread(StgTSO *tso)
           last = &t->link, t = t->link) {
        if (t == tso) {
          *last = tso->link;
-         break;
+         goto done;
        }
       }
+      barf("unblockThread (BLACKHOLE): TSO not found");
     }
 
   default:
     barf("unblockThread");
   }
 
+ done:
   tso->link = END_TSO_QUEUE;
   tso->blocked_on = NULL;
+  PUSH_ON_RUN_QUEUE(tso);
 }
 
 /* -----------------------------------------------------------------------------
@@ -755,10 +771,6 @@ raiseAsync(StgTSO *tso, StgClosure *exception)
       tso->su = cf->link;
       tso->sp = sp;
       tso->whatNext = ThreadEnterGHC;
-      /* wake up the thread */
-      if (tso->link == END_TSO_QUEUE) {
-       PUSH_ON_RUN_QUEUE(tso);
-      }
       return;
     }