[project @ 2002-02-05 10:06:24 by simonmar]
authorsimonmar <unknown>
Tue, 5 Feb 2002 10:06:24 +0000 (10:06 +0000)
committersimonmar <unknown>
Tue, 5 Feb 2002 10:06:24 +0000 (10:06 +0000)
Fix bad bugs in deleteAllThreds: we were looping through the thread
queues calling deleteThread() on each thread as we go, but calling
deleteThread() has the side effect of removing the thread from the
relevant queue, so we would end up breaking out of the loop after
processing only a single thread.

This may fix problems like "resurrectThreads: thread blocked in a
strange way" seen after pressing ^C.

Aside: we really shouldn't be using deleteThread() at all, since it
doesn't give the thread a chance to clean up & release locks.  To be
well-behaved a program has to catch ^C itself at the moment.

ghc/rts/Schedule.c

index ab008fd..d5e6936 100644 (file)
@@ -1,5 +1,5 @@
 /* ---------------------------------------------------------------------------
- * $Id: Schedule.c,v 1.116 2002/02/04 20:56:53 sof Exp $
+ * $Id: Schedule.c,v 1.117 2002/02/05 10:06:24 simonmar Exp $
  *
  * (c) The GHC Team, 1998-2000
  *
@@ -1452,15 +1452,18 @@ schedule( void )
    
 void deleteAllThreads ( void )
 {
-  StgTSO* t;
+  StgTSO* t, *next;
   IF_DEBUG(scheduler,sched_belch("deleting all threads"));
-  for (t = run_queue_hd; t != END_TSO_QUEUE; t = t->link) {
+  for (t = run_queue_hd; t != END_TSO_QUEUE; t = next) {
+      next = t->link;
       deleteThread(t);
   }
-  for (t = blocked_queue_hd; t != END_TSO_QUEUE; t = t->link) {
+  for (t = blocked_queue_hd; t != END_TSO_QUEUE; t = next) {
+      next = t->link;
       deleteThread(t);
   }
-  for (t = sleeping_queue; t != END_TSO_QUEUE; t = t->link) {
+  for (t = sleeping_queue; t != END_TSO_QUEUE; t = next) {
+      next = t->link;
       deleteThread(t);
   }
   run_queue_hd = run_queue_tl = END_TSO_QUEUE;