3 ms·
It's more like thread cancellation than an interrupt. Few languages do cancellation well. Either it doesn't work right, or it does something overly elaborate l
by Animats 9y ago
It's more like thread cancellation than an interrupt.
Few languages do cancellation well. Either it doesn't work right, or it does something overly elaborate like LISP breaks.
- evincarofautumn 9y agoI actually like the way it is (or can be) done in Haskell: since polling an “interrupted” status would be a side effect, instead they turn the problem on its head: you can throw an async exception to the task you want to interrupt, given its ID, and it behaves essentially as if the code it was just executing has thrown a synchronous exception. Sounds spooky, and it does require writing code in an exception-safe way, but that’s generally easy: pure code is largely exception-safe by nature, and impure code can use “bracket” (“finally”, “mask”, “ResourceT”, &c.) to acquire & release resources—and should already be using these functions anyway to handle regular synchronous exceptions. Async exceptions are very useful for killing a task that’s using too much time/memory, or initiating a graceful shutdown.
- anameaname 9y agoI've use Go's context based cancellation, and while I like the paradigm, it's kind of verbose. There are some that say that since it has to be passed everywhere, and can store values, it's equal to Goroutine-local storage. I'm would be surprised if they don't include a formalization in the language itself in version 2.