Proposal: Add Control.Exception.allowInterrupt

Ticket: http://hackage.haskell.org/trac/ghc/ticket/4857 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 () The above is almost the entire implementation modulo imports, so I didn't bother attaching a patch to the ticket. unsafeUnmask is not exported by Control.Exception, it is an internal function from GHC.IO. Some discussion leading up to this can be found in http://hackage.haskell.org/trac/ghc/ticket/3837. Discussion period: 3 weeks (until 12 Jan 2011) Cheers, Simon

On 22/12/2010 10:37, Simon Marlow wrote:
Some discussion leading up to this can be found in http://hackage.haskell.org/trac/ghc/ticket/3837.
Oops, I meant http://hackage.haskell.org/trac/ghc/ticket/4810

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 ) -Isaac

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

+1
On Wed, 22 Dec 2010 19:37:55 +0900, Simon Marlow
Ticket:
http://hackage.haskell.org/trac/ghc/ticket/4857
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 ()
The above is almost the entire implementation modulo imports, so I didn't bother attaching a patch to the ticket. unsafeUnmask is not exported by Control.Exception, it is an internal function from GHC.IO.
Some discussion leading up to this can be found in http://hackage.haskell.org/trac/ghc/ticket/3837.
Discussion period: 3 weeks (until 12 Jan 2011)
-- shelarcy <shelarcy hotmail.co.jp> http://page.freett.com/shelarcy/
participants (3)
-
Isaac Dupree
-
shelarcy
-
Simon Marlow