What does interruptibility mean exactly?

Hello, 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. or: 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. Regards, Bas [1] http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/Control-Excep... [2] darcs get http://code.haskell.org/~basvandijk/code/threads/

v.dijk.bas:
Hello,
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..."
I think the best definition of interruptible is in this paper: www.haskell.org/~simonmar/papers/async.pdf Section 5.3

On Mon, Jun 14, 2010 at 11:20 PM, Don Stewart
v.dijk.bas:
Hello,
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..."
I think the best definition of interruptible is in this paper:
www.haskell.org/~simonmar/papers/async.pdf
Section 5.3
Thanks for the link Don! Next time I will re-read the paper before asking ;-) The definition makes it clear indeed: "Any operation which may need to wait indefinitely for a resource (e.g., takeMVar) may receive asynchronous exceptions even within an enclosing block, BUT ONLY WHILE THE RESOURCE IS UNAVAILABLE" So I guess I can update my threads package to use MVars again. Nice! because they were a bit faster in an informal benchmark I performed some time ago. A later quote from 5.3 emphasizes the definition even more: "...an interruptible operation cannot be interrupted if the resource it is attempting to acquire is always available..." The following darcs patch makes the definition of interruptibility in the documentation in Control.Exception a bit clearer in this regard: http://bifunctor.homelinux.net/~bas/doc-interruptibility.dpatch Regards, Bas

On 15/06/2010 09:00, Bas van Dijk wrote:
On Mon, Jun 14, 2010 at 11:20 PM, Don Stewart
wrote: v.dijk.bas:
Hello,
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..."
I think the best definition of interruptible is in this paper:
www.haskell.org/~simonmar/papers/async.pdf
Section 5.3
Thanks for the link Don! Next time I will re-read the paper before asking ;-)
The definition makes it clear indeed:
"Any operation which may need to wait indefinitely for a resource (e.g., takeMVar) may receive asynchronous exceptions even within an enclosing block, BUT ONLY WHILE THE RESOURCE IS UNAVAILABLE"
So I guess I can update my threads package to use MVars again. Nice! because they were a bit faster in an informal benchmark I performed some time ago.
This is currently true for takeMVar/putMVar but it is no longer true for throwTo (in 6.14+). I'll update the docs to make that clear. The reason is that throwTo now works by message passing when the target is on another CPU, and we consider a thread that is waiting for a response to a message to be blocked - even if the throwTo can in fact proceed immediately because the target is interruptible. Cheers, Simon
A later quote from 5.3 emphasizes the definition even more:
"...an interruptible operation cannot be interrupted if the resource it is attempting to acquire is always available..."
The following darcs patch makes the definition of interruptibility in the documentation in Control.Exception a bit clearer in this regard:
http://bifunctor.homelinux.net/~bas/doc-interruptibility.dpatch
Regards,
Bas _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

On Tue, Jun 15, 2010 at 12:41 PM, Simon Marlow
On 15/06/2010 09:00, Bas van Dijk wrote:
On Mon, Jun 14, 2010 at 11:20 PM, Don Stewart
wrote: v.dijk.bas:
Hello,
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..."
I think the best definition of interruptible is in this paper:
www.haskell.org/~simonmar/papers/async.pdf
Section 5.3
Thanks for the link Don! Next time I will re-read the paper before asking ;-)
The definition makes it clear indeed:
"Any operation which may need to wait indefinitely for a resource (e.g., takeMVar) may receive asynchronous exceptions even within an enclosing block, BUT ONLY WHILE THE RESOURCE IS UNAVAILABLE"
So I guess I can update my threads package to use MVars again. Nice! because they were a bit faster in an informal benchmark I performed some time ago.
This is currently true for takeMVar/putMVar but it is no longer true for throwTo (in 6.14+). I'll update the docs to make that clear. The reason is that throwTo now works by message passing when the target is on another CPU, and we consider a thread that is waiting for a response to a message to be blocked - even if the throwTo can in fact proceed immediately because the target is interruptible.
Thanks for the heads-up. BTW I just released threads-0.3 which, among other things, uses MVars again for waiting for the termination of a thread: http://hackage.haskell.org/package/threads-0.3 Regards, Bas

It seems to me that the documentation could be further refined:
An acquisition operation cannot be interrupted when the requested resource is available; the resource is successfully acquired and the subsequent computation can proceed. On the other hand, if the resource is unavailable, then the acquisition operation is in a blocked state and can be interrupted.
I'm not sure that this is the exact phrasing, but it does convey the meaning a bit more clearly. Also missing is that interruptable implies restartable.
Sent from my Verizon Wireless BlackBerry
-----Original Message-----
From: Bas van Dijk
On 15/06/2010 09:00, Bas van Dijk wrote:
On Mon, Jun 14, 2010 at 11:20 PM, Don Stewart
wrote: v.dijk.bas:
Hello,
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..."
I think the best definition of interruptible is in this paper:
www.haskell.org/~simonmar/papers/async.pdf
Section 5.3
Thanks for the link Don! Next time I will re-read the paper before asking ;-)
The definition makes it clear indeed:
"Any operation which may need to wait indefinitely for a resource (e.g., takeMVar) may receive asynchronous exceptions even within an enclosing block, BUT ONLY WHILE THE RESOURCE IS UNAVAILABLE"
So I guess I can update my threads package to use MVars again. Nice! because they were a bit faster in an informal benchmark I performed some time ago.
This is currently true for takeMVar/putMVar but it is no longer true for throwTo (in 6.14+). I'll update the docs to make that clear. The reason is that throwTo now works by message passing when the target is on another CPU, and we consider a thread that is waiting for a response to a message to be blocked - even if the throwTo can in fact proceed immediately because the target is interruptible.
Thanks for the heads-up. BTW I just released threads-0.3 which, among other things, uses MVars again for waiting for the termination of a thread: http://hackage.haskell.org/package/threads-0.3 Regards, Bas _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
participants (4)
-
Bas van Dijk
-
Don Stewart
-
scooter.phd@gmail.com
-
Simon Marlow