[Haskell-cafe] Re: Cleaning up threads

Simon Marlow marlowsd at gmail.com
Wed Sep 22 04:21:57 EDT 2010


On 22/09/2010 02:18, Mitar wrote:
> Hi!
>
> On Tue, Sep 21, 2010 at 11:10 PM, Simon Marlow<marlowsd at gmail.com>  wrote:
>> So rather than admitting defeat here I'd like to see it become the norm to
>> write async-exception-safe code.
>
> This is also what I think. You have to make your code work with
> exceptions, because they will come sooner or later. So if you handle
> them properly, once you have this implemented, then you can easily use
> them also for your own stuff.
>
>> It's not that hard, especially with the new mask API coming in GHC 7.0.
>
> Not hard? I see it almost impossible without mask. You cannot have
> arbitrary long cleanup functions in for example bracket because
> somebody can (and will) interrupt it even if you block, because some
> function somewhere deep bellow will unblock.

mask doesn't save you from this, because a function in a library below 
you might perform an interruptible operation like takeMVar, and that 
operation could receive another asynchronous exception.  You could use 
maskUninterruptible, but that's not a good solution either - if an 
operation during cleanup really does block, you'd like to be able to 
Control-C your way out.

So the only way out of this hole is: don't write long cleanup code that 
needs to mask exceptions.  Find another way to do it.

Cheers,
	Simon


More information about the Haskell-Cafe mailing list