Evan Martin (evan) wrote in evan_tech,
Evan Martin

asynchronous exceptions

LTU linked to Asynchronous Exceptions in Haskell. It has an amusing resolution.

They posit: Sometimes it's nice to be able to kill another thread, either because of timeouts, or user interrupts, etc. But you can't safely do it because that thread could potentially be holding locks or leaving resources in an unsafe state. What to do?

Most languages avoid killing and just require a worker thread to poll a shared flag to see whether it's time to stop. (LogJam on Windows did this at one point for cancelling threaded network requests -- you don't really cancel them, you just tell them to stop when they get the chance and hide the "processing" dialog.) This is lame, but it's just what you do.

The main conclusion is that crazy Haskell again gets nice properties for free:
While the semi-asychronous approach avoids breaking synchronization abstractions, it is non-modular in that the target code must be written to use the signalling mechanism. Worse still (for us), the semi-asynchronous approach is simply incompatible with a purely-functional language, such as Concurrent Haskell. The problem is that polling a global flag is not a functional operation, yet in a Concurrent Haskell program, most of the time is spent in purely-functional code. On the other hand, since there is absolutely no problem with abandoning a purely-functional computation at any point, asynchronous exceptions are safe in a functional setting.
Tags: haskell, programming languages

  • blog moved

    As described elsewhere, I've quit LiveJournal. If you're interested in my continuing posts, you should look at one of these (each contains feed…

  • dremel

    They published a paper on Dremel, my favorite previously-unpublished tool from the Google toolchest. Greg Linden discusses it: "[...] it is capable…

  • treemaps

    I finally wrote up my recent adventures in treemapping, complete with nifty clickable visualizations.

  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.