News for hackers. Stuff that matters.
Re:Asynchronous Exceptions in Practice by jerf on Tuesday January 24, 2017 @09:56AM (#13471746)
The problem with asynchronous exceptions in languages with unconstrained mutability and effects is that there is no way to guarantee what happens when you get the asynchronous exception, especially when you get another one while the handler is running, and maybe another one while that is running, etc. You can be in the middle of an arbitrary sequence of mutations that you don't expect to be interrupted, in a critical section protected by any number of mutexes or whatever, and then the exception arrives when you weren't expecting it. Then while handling that, another one arrives in the middle of your handler. It turns out there just isn't a solution to this problem for languages that don't have constrained mutation.

In Haskell, this turns out to be an occasionally challenging problem rather than an impossible one. As the article said, it does get tricky near a few of the seams, but in most code you can just ignore the problem and not worry about it. Your immutable computation gets interrupted at an arbitrary location in the middle of it, and you just throw away the pure components of the computation and run the cleanup code from "bracket"s. (And other runtime details.)

It's the same reason Haskell has usable STM and languages with unconstrained effects do not. (Yes, you can download libraries that are STM for a lot of languages, but they are generally not usable.) In a language with unconstrained mutation and side effects, you can't reasonably roll back a transaction because you can't undo the effects, and you can't constrain the programmer to not use any effects. As it turns out, STM turned out not to be a silver bullet and it's merely a single tool in Haskell's toolbelt, one that isn't even necessarily used that often, but because Haskell could implement it, the Haskell community was able to discover that by using it, rather than just theorizing about how nice it may or may not be if only we could have an implementation.

There are no comments on this comment yet.