throwTo :: Exception e => ThreadId -> e -> IO ()
base Control.Exception.Base, base GHC.Conc.Sync, base Control.Exception, base GHC.Conc, base Control.Concurrent, base Control.OldException
throwTo raises an arbitrary exception in the target thread (GHC only). throwTo does not return until the exception has been raised in the target thread. The calling thread can thus be certain that the target thread has received the exception. This is a useful property to know when dealing with race conditions: eg. if there are two threads that can kill each other, it is guaranteed that only one of the threads will get to kill the other. Whatever work the target thread was doing when the exception was raised is not lost: the computation is suspended until required by another thread. If the target thread is currently making a foreign call, then the exception will not be raised (and hence throwTo will not return) until the call has completed. This is the case regardless of whether the call is inside a mask or not. However, in GHC a foreign call can be annotated as interruptible, in which case a throwTo will cause the RTS to attempt to cause the call to return; see the GHC documentation for more details. Important note: the behaviour of throwTo differs from that described in the paper "Asynchronous exceptions in Haskell" ( In the paper, throwTo is non-blocking; but the library implementation adopts a more synchronous design in which throwTo does not return until the exception is received by the target thread. The trade-off is discussed in Section 9 of the paper. Like any blocking operation, throwTo is therefore interruptible (see Section 5.3 of the paper). Unlike other interruptible operations, however, throwTo is always interruptible, even if it does not actually block. There is no guarantee that the exception will be delivered promptly, although the runtime will endeavour to ensure that arbitrary delays don't occur. In GHC, an exception can only be raised when a thread reaches a safe point, allocation occurs. Some loops do not perform any memory allocation inside the loop and therefore cannot be interrupted by a throwTo. Blocked throwTo is fair: if multiple threads are trying to throw an exception to the same target thread, they will succeed in FIFO order.