[Haskell-cafe] Re: Cleaning up threads

Ertugrul Soeylemez es at ertes.de
Tue Sep 14 20:16:10 EDT 2010


"Edward Z. Yang" <ezyang at MIT.EDU> wrote:

> Excerpts from Ertugrul Soeylemez's message of Mon Sep 13 03:03:11 -0400 2010:
> > In general it's better to avoid using killThread.  There are much
> > cleaner ways to tell a thread to exit.
>
> This advice doesn't really apply to Haskell: in fact, the GHC
> developers have thought really carefully about this:
>
>     http://research.microsoft.com/en-us/um/people/simonpj/papers/asynch-exns.ps.gz
>
> Pure code can always be safely asynchronously interrupted (even code
> using state like the ST monad), and IO code can be made to interact
> correctly with thread termination simply by using appropriate
> bracketing functions that would handle normal IO exceptions.

The point is that killThread throws an exception.  An exception is
usually an error condition.  My approach strictly separates an
unexpected crash from an intended quit.  After all an application
exiting normally shouldn't be an exception (i.e. something unexpected).

Also using the Quit command from my example you can actually wait for
the thread to finish cleanup work.  You can't do this with an exception.


Greets,
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/




More information about the Haskell-Cafe mailing list