What does interruptibility mean exactly?

Bas van Dijk v.dijk.bas at gmail.com
Mon Jun 14 17:17:41 EDT 2010


I've a short question about interruptible operations. In the following
program is it possible for 'putMVar' to re-throw asynchronous
exceptions even when asynchronous exception are blocked/masked?

  newEmptyMVar >>= \mv -> block $ putMVar mv x

The documentation in Control.Exception about interruptible
operations[1] confused me:

"Some operations are interruptible, which means that they can receive
asynchronous exceptions even in the scope of a block. Any function
which may itself block is defined as interruptible..."

Do I need to interpret this as:

1) 'putMVar' is always interruptible because it's an operation that
has the ability to block. For example when applied to a full MVar.


2) 'putMVar' is only interruptible when it actually blocks and not
interruptible when it is sure that it will not block. For example when
applied to an empty MVar like in the given program.

The reason I'm asking is that in my threads library[2] I previously
applied 'putMVar' to an empty MVar to signal the termination of a
thread. However due to some comments in the topic about "Asynchronous
Exception Wormholes" I got a bit scared that 'putMVar' might throw
exceptions even in the scope of a block. Because this could cause
dead-locks in my threads library, I rewrote it using TMVars which
don't have interruptible operations. However, I'm still not sure about
the exact semantics so I would like to clear this up.



[1] http://haskell.org/ghc/docs/6.12.1/html/libraries/base-
[2] darcs get http://code.haskell.org/~basvandijk/code/threads/

More information about the Glasgow-haskell-users mailing list