2 issues and 1 proposal for runInUnboundThread

Bas van Dijk v.dijk.bas at gmail.com
Sat Oct 30 11:10:41 EDT 2010


On Tue, Oct 26, 2010 at 2:24 PM, Bas van Dijk <v.dijk.bas at gmail.com> wrote:
> On Fri, Oct 15, 2010 at 12:00 AM, Bas van Dijk <v.dijk.bas at gmail.com> 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
>>
>> The patch bundle attached to the ticket fixes the two issues and
>> implements the above behavior.
>>
>> Discussion deadline:
>>
>> I don't think the fixes for the issues need discussion. They only need
>> a review from one of the GHC devs.
>>
>> With regard to the proposal I propose a discussion deadline of 2 weeks
>> from now: Thursday 28 October.
>>
>> Ticket: http://hackage.haskell.org/trac/ghc/ticket/4400
>>
>> Regards,
>>
>> Bas
>>
>
> There're 2 days left for this proposal. Any more opinions?
>
> Thanks,
>
> Bas
>

The deadline for this proposal has passed. There was little interest
but no objections so I'm moving the ticket to 'patch'.

Thanks,

Bas


More information about the Libraries mailing list