Re: [Haskell-cafe] Cleaning up threads

2010-09-14 Thread Bas van Dijk
Note that killing the main thread will also kill all other threads. See: http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/Control-Concurrent.html#11 You can use my threads library to wait on a child thread and possibly re-raise an exception that was thrown in or to it:

Re: [Haskell-cafe] Cleaning up threads

2010-09-14 Thread Mitar
Hi! On Tue, Sep 14, 2010 at 11:46 PM, Bas van Dijk v.dijk@gmail.com wrote: Note that killing the main thread will also kill all other threads. See: Yes. But how does those other threads have time to cleanup is my question. You can use my threads library to wait on a child thread and

Re: [Haskell-cafe] Cleaning up threads

2010-09-14 Thread Gregory Collins
Mitar mmi...@gmail.com writes: Hi! On Tue, Sep 14, 2010 at 11:46 PM, Bas van Dijk v.dijk@gmail.com wrote: Note that killing the main thread will also kill all other threads. See: Yes. But how does those other threads have time to cleanup is my question. What we do in Snap is this: the

Re: [Haskell-cafe] Cleaning up threads

2010-09-14 Thread Bas van Dijk
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!

Re: [Haskell-cafe] Cleaning up threads

2010-09-14 Thread Gregory Collins
Bas van Dijk v.dijk@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

Re: [Haskell-cafe] Cleaning up threads

2010-09-14 Thread Bas van Dijk
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[1] but I would advise to fix the code right now