handle ThreadMigrating in throwTo() (#4811)
authorSimon Marlow <marlowsd@gmail.com>
Fri, 3 Dec 2010 09:48:18 +0000 (09:48 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Fri, 3 Dec 2010 09:48:18 +0000 (09:48 +0000)
If a throwTo targets a thread that has just been created with
forkOnIO, then it is possible the exception strikes while the thread
is still in the process of migrating.  throwTo() didn't handle this
case, but it's fairly straightforward.

rts/RaiseAsync.c

index 628dff8..3cfb450 100644 (file)
@@ -436,6 +436,18 @@ check_target:
        }
 #endif
 
+    case ThreadMigrating:
+        // if is is ThreadMigrating and tso->cap is ours, then it
+        // *must* be migrating *to* this capability.  If it were
+        // migrating away from the capability, then tso->cap would
+        // point to the destination.
+        //
+        // There is a MSG_WAKEUP in the message queue for this thread,
+        // but we can just do it preemptively:
+        tryWakeupThread(cap, target);
+        // and now retry, the thread should be runnable.
+        goto retry;
+
     default:
        barf("throwTo: unrecognised why_blocked value");
     }