Re: [Haskell-cafe] Re: Cleaning up threads

2010-09-22 Thread Bas van Dijk
On Wed, Sep 22, 2010 at 3:18 AM, Mitar mmi...@gmail.com wrote: What would I also like to see in Haskell is that it would be somehow possible to see which all exceptions could your function (through used functions there) throw. In this way it would be really possible to make

Re: [Haskell-cafe] Re: Cleaning up threads

2010-09-22 Thread Simon Marlow
On 22/09/2010 02:18, Mitar wrote: Hi! On Tue, Sep 21, 2010 at 11:10 PM, Simon Marlowmarlo...@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

Re: [Haskell-cafe] Re: Cleaning up threads

2010-09-22 Thread Mitar
Hi! On Wed, Sep 22, 2010 at 10:21 AM, Simon Marlow marlo...@gmail.com wrote:  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 maybe this shows a need for

Re: [Haskell-cafe] Re: Cleaning up threads

2010-09-22 Thread Simon Marlow
On 22/09/2010 09:51, Mitar wrote: Hi! On Wed, Sep 22, 2010 at 10:21 AM, Simon Marlowmarlo...@gmail.com wrote: 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

[Haskell-cafe] Re: Cleaning up threads

2010-09-21 Thread Simon Marlow
On 14/09/10 19:29, Bryan O'Sullivan wrote: On Tue, Sep 14, 2010 at 11:21 AM, Edward Z. Yang ezy...@mit.edu mailto:ezy...@mit.edu wrote: 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

Re: [Haskell-cafe] Re: Cleaning up threads

2010-09-21 Thread Mitar
Hi! On Tue, Sep 21, 2010 at 11:10 PM, Simon Marlow marlo...@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

Re: [Haskell-cafe] Re: Cleaning up threads

2010-09-14 Thread Edward Z. Yang
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

Re: [Haskell-cafe] Re: Cleaning up threads

2010-09-14 Thread Bryan O'Sullivan
On Tue, Sep 14, 2010 at 11:21 AM, Edward Z. Yang ezy...@mit.edu wrote: 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

Re: [Haskell-cafe] Re: Cleaning up threads

2010-09-14 Thread Evan Laforge
Ertugrul's advice is still correct. I'd wager there are very few concurrent applications that could survive a killThread without disaster. People simply don't write or test code with that in mind, and even when they do, it's more likely than not to be wrong. Does this apply to pure code? I

Re: [Haskell-cafe] Re: Cleaning up threads

2010-09-14 Thread Gregory Collins
Bryan O'Sullivan b...@serpentine.com writes: On Tue, Sep 14, 2010 at 11:21 AM, Edward Z. Yang ezy...@mit.edu wrote: 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

Re: [Haskell-cafe] Re: Cleaning up threads

2010-09-14 Thread Bryan O'Sullivan
On Tue, Sep 14, 2010 at 12:04 PM, Gregory Collins g...@gregorycollins.netwrote: That's surprising to me -- this is how we kill the Snap webserver (killThread the controlling thread...). It's one thing to design code to work that way and test it all the time, but it would be quite another to

Re: [Haskell-cafe] Re: Cleaning up threads

2010-09-14 Thread Mitar
Hi! On Tue, Sep 14, 2010 at 9:04 PM, Gregory Collins g...@gregorycollins.net wrote: That's surprising to me -- this is how we kill the Snap webserver (killThread the controlling thread...). Yes. This does work. The only problem is that my main thread then kills child threads, which then start

Re: [Haskell-cafe] Re: Cleaning up threads

2010-09-14 Thread Ben Millwood
On Tue, Sep 14, 2010 at 9:44 PM, Mitar mmi...@gmail.com wrote: Hi! On Tue, Sep 14, 2010 at 9:04 PM, Gregory Collins g...@gregorycollins.net wrote: That's surprising to me -- this is how we kill the Snap webserver (killThread the controlling thread...). Yes. This does work. The only problem

[Haskell-cafe] Re: Cleaning up threads

2010-09-14 Thread Ertugrul Soeylemez
Edward Z. Yang ezy...@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

Re: [Haskell-cafe] Re: Cleaning up threads

2010-09-14 Thread Mitar
Hi! On Wed, Sep 15, 2010 at 2:16 AM, Ertugrul Soeylemez e...@ertes.de wrote: The point is that killThread throws an exception.  An exception is usually an error condition. This is reasoning based on nomenclature. If exceptions were named Signal or Interrupt?  My approach strictly separates an

Re: [Haskell-cafe] Re: Cleaning up threads

2010-09-14 Thread David Leimbach
On Tue, Sep 14, 2010 at 11:29 AM, Bryan O'Sullivan b...@serpentine.comwrote: On Tue, Sep 14, 2010 at 11:21 AM, Edward Z. Yang ezy...@mit.edu wrote: Pure code can always be safely asynchronously interrupted (even code using state like the ST monad), and IO code can be made to interact

[Haskell-cafe] Re: Cleaning up threads

2010-09-14 Thread Ertugrul Soeylemez
Mitar mmi...@gmail.com wrote: On Wed, Sep 15, 2010 at 2:16 AM, Ertugrul Soeylemez e...@ertes.de wrote: The point is that killThread throws an exception.  An exception is usually an error condition. This is reasoning based on nomenclature. If exceptions were named Signal or Interrupt?  

[Haskell-cafe] Re: Cleaning up threads

2010-09-13 Thread Ertugrul Soeylemez
Mitar mmi...@gmail.com wrote: I run multiple threads where I would like that exception from any of them (and main) propagate to others but at the same time that they can gracefully cleanup after themselves (even if this means not exiting). I have this code to try, but cleanup functions (stop)