From: simonpj@microsoft Date: Mon, 11 Dec 2006 12:22:57 +0000 (+0000) Subject: Add note about synhronous delivery of throwTo X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=945d583470fa9bee6c5c1e652e2be9241deffc25;p=haskell-directory.git Add note about synhronous delivery of throwTo --- diff --git a/GHC/Conc.lhs b/GHC/Conc.lhs index 461a3bf..9e09672 100644 --- a/GHC/Conc.lhs +++ b/GHC/Conc.lhs @@ -221,7 +221,8 @@ killThread tid = throwTo tid (AsyncException ThreadKilled) {- | '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 +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 @@ -231,6 +232,16 @@ 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 'block' or not. + +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 8 of the paper. +Like any blocking operation, 'throwTo' is therefore interruptible (see Section 4.3 of +the paper). + -} throwTo :: ThreadId -> Exception -> IO () throwTo (ThreadId id) ex = IO $ \ s ->