Proposal: Add Control.Exception.allowInterrupt

Simon Marlow marlowsd at gmail.com
Tue Jan 4 15:31:34 CET 2011


On 23/12/2010 19:39, Isaac Dupree wrote:
> On 12/22/10 05:37, Simon Marlow wrote:
>> This proposal is to add the following function to Control.Exception:
>>
>> -- | When invoked inside 'mask', this function allows a blocked
>> -- asynchronous exception to be raised, if one exists. It is
>> -- equivalent to performing an interruptible operation (see
>> -- #interruptible#), but does not involve any actual blocking.
>> --
>> -- When called outside 'mask', or inside 'uninterruptibleMask', this
>> -- function has no effect.
>> allowInterrupt :: IO ()
>> allowInterrupt = unsafeUnmask $ return ()
>
> Can you summarize the rationale? I didn't easily figure it out by
> skimming the long thread you referenced (
> http://hackage.haskell.org/trac/ghc/ticket/4810 )

It lets you poll for exceptions inside mask.  There's no reasonable way 
to do this currently.  It would be useful if you were spending a lot of 
time inside mask and could identify a place where it would be safe to 
allow asynchronous exceptions to be raised.

If you think of 'mask' as 'switch to polling mode for a while', then 
this is the way to do manual polling.  Polling is already built-in for 
blocking functions, like takeMVar.  Perhaps you want to use polling 
rather than asynchronous mode globally - allowInterrupt makes it 
feasible to do that (not that I think we should recommend doing that, 
but I can imagine it might make sense in heavily imperative code).

Cheers,
	Simon



More information about the Libraries mailing list