[Haskell-cafe] Cleaning up threads
Bas van Dijk
v.dijk.bas at gmail.com
Wed Sep 15 01:55:48 EDT 2010
Also don't forget to unblock asynchronous exceptions inside
'someWorkToDo' otherwise you can't throw exceptions to the thread.
Note that 'finally' unblocks asynchronous exceptions but I consider
this a bug. In the upcoming base library this is fixed but I would
advise to fix the code right now to not be surprised later.
Also note that the threads library correctly unblocks asynchronous
exceptions when necessary.
On Wed, Sep 15, 2010 at 7:38 AM, Gregory Collins
<greg at gregorycollins.net> wrote:
> Bas van Dijk <v.dijk.bas at gmail.com> writes:
>> Don't forget to block asynchronous exception _before_ you fork in:
>>> tid <- forkIO (someWorkToDo `finally` putMVar mv ())
>> Otherwise an asynchronous exception might be thrown to the thread
>> _before_ the 'putMVar mv ()' exception handler is installed leaving
>> your main thread in a dead-lock!
> Good catch, thank you,
> Gregory Collins <greg at gregorycollins.net>
More information about the Haskell-Cafe