Evan Martin (evan) wrote in evan_tech,
Evan Martin
evan
evan_tech

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
Subscribe

  • no go

    Two friends of mine were pretty enthusiastic about the Go language, so I tried writing a program in it yesterday. It is frustrating because despite…

  • playing with vala

    I actually was toying with making something like Vala back in college. It's pretty cute. Much like using the sane subset of C++, as you write code…

  • chromium.el

    This weekend I wrote some Emacs Lisp to write some utility functions I find useful for hacking on Chromium. It's fun to have a reason to use Lisp!…

  • Post a new comment

    Error

    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.
  • 2 comments