#4400: Asynchronous exceptions in runInUnboundThread ---------------------------------+------------------------------------------ Reporter: basvandijk | Owner: Type: proposal | Status: new Priority: normal | Component: libraries/base Version: 6.12.3 | Keywords: Testcase: | Blockedby: Os: Unknown/Multiple | Blocking: Architecture: Unknown/Multiple | Failure: None/Unknown ---------------------------------+------------------------------------------ When you throw an asynchronous exception to a thread which is executing: `runInUnboundThread m`, `m` will keep executing and there's no way to kill it.
I propose to catch asynchronous exceptions in `runInUnboundThread` and throw them to the thread which is executing `m`. `m` in turn can decide to catch or ignore them. In case `m` decides to ignore them or to rethrow them, the exception will be rethrown in the current thread: {{{ runInUnboundThread :: IO a -> IO a runInUnboundThread action = do bound <- isCurrentThreadBound if bound then do mv <- newEmptyMVar mask $ \restore -> do tid <- forkIO $ Exception.try (restore action) >>= putMVar mv let wait = takeMVar mv `Exception.catch` \(e :: SomeException) -> Exception.throwTo tid e >> wait wait >>= unsafeResult else action unsafeResult :: Either SomeException a -> IO a unsafeResult = either Exception.throwIO return }}} The attached patch implements this behaviour. (Note there are two other bug-fix patches in the bundle that this patch depends on which can be independently applied.) -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4400> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs