removeThreadFromQueue: stub out the link field before returning (#4813)
[ghc-hetmet.git] / rts / Threads.c
index 7344134..f6b1bac 100644 (file)
@@ -163,9 +163,11 @@ removeThreadFromQueue (Capability *cap, StgTSO **queue, StgTSO *tso)
        if (t == tso) {
            if (prev) {
                setTSOLink(cap,prev,t->_link);
+                t->_link = END_TSO_QUEUE;
                 return rtsFalse;
            } else {
                *queue = t->_link;
+                t->_link = END_TSO_QUEUE;
                 return rtsTrue;
            }
        }
@@ -190,7 +192,8 @@ removeThreadFromDeQueue (Capability *cap,
                *head = t->_link;
                 flag = rtsTrue;
            }
-           if (*tail == tso) {
+            t->_link = END_TSO_QUEUE;
+            if (*tail == tso) {
                if (prev) {
                    *tail = prev;
                } else {
@@ -284,6 +287,19 @@ unblock:
     // we'll block again.
     tso->why_blocked = NotBlocked;
     appendToRunQueue(cap,tso);
+
+    // We used to set the context switch flag here, which would
+    // trigger a context switch a short time in the future (at the end
+    // of the current nursery block).  The idea is that we have just
+    // woken up a thread, so we may need to load-balance and migrate
+    // threads to other CPUs.  On the other hand, setting the context
+    // switch flag here unfairly penalises the current thread by
+    // yielding its time slice too early.
+    //
+    // The synthetic benchmark nofib/smp/chan can be used to show the
+    // difference quite clearly.
+
+    // cap->context_switch = 1;
 }
 
 /* ----------------------------------------------------------------------------