[Haskell-cafe] Re: Asynchronous exception wormholes kill
modularity
Bas van Dijk
v.dijk.bas at gmail.com
Thu Apr 8 17:45:41 EDT 2010
On Thu, Apr 8, 2010 at 9:15 PM, Isaac Dupree
<ml at isaac.cedarswampstudios.org> wrote:
> I still would like to see examples of where it's needed, because I slightly
> suspect that wrapping possibly-blocking operations in an exception handler
> that does something appropriate, along with ordinary 'mask', might be
> sufficient... But I expect to be proved wrong; I just haven't figured out
> how to prove myself wrong.
Take my threads package, I uploaded to hackage yesterday, as an example.
In Control.Concurrent.Thread.Group.fork I first increment numThreads
before forking. When the fork thread terminates it should decrement
numThreads and release the lock when it reaches zero so that potential
waiters are woken up:
http://hackage.haskell.org/packages/archive/threads/0.1/doc/html/src/Control-Concurrent-Thread-Group.html#fork
Now if an asynchronous exception is thrown during the takeMVar in
decrement there's no way I can prevent not releasing the lock causing
the waiters to deadlock.
This could be solved by wrapping decrement in nonInterruptibleMask.
regards,
Bas
More information about the Haskell-Cafe
mailing list