2 issues and 1 proposal for runInUnboundThread
Simon Marlow
marlowsd at gmail.com
Thu Oct 21 05:29:17 EDT 2010
On 14/10/2010 23:00, Bas van Dijk wrote:
> Hello,
>
> I found two small issues in Control.Concurrent:
>
> * Both runInBoundThread and runInUnboundThread use throw instead of
> throwIO. It's nicer to use throwIO in an IO context instead of throw
> because it guarantees ordering with respect to other IO actions.
>
> * runInUnboundThread explicitly checks the blocked status of the
> current thread which is redundant because mask also performs this
> check.
>
> I also have a new proposal:
>
> 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
I think it's ok, no objections here. Do you have a use for
runInUnboundThread, incidentally?
Cheers,
Simon
More information about the Libraries
mailing list