Hi Stuart, > One option would be to use a second agent as a flag. My really-long- > action function could periodically check the value of that agent, and > terminate if it's been set to true. But would it be possible to > provide a generic interrupt mechanism that doesn't require modifying > the action function?
Futures have a cancel method which *attempts* to cancel a task. My understanding is that this is a pretty good way to cancel most tasks, but does not cover all cases (Non-interruptible Blocking). Here is an example of how you might take advantage of that: http://github.com/timothypratley/strive/blob/d21fb78ddf00e8e79dd4a27ee55964e6a75c26ab/src/clj/futures.clj When I watch my CPU usage this behaves as I would expect it (ie: canceling the task correctly). I believe Agents could be adjusted in a similar fashion with reasonable ease, by replacing execute with submit and holding a reference to it as the currently running task. Alternatively just implementing the same cancellation strategy as futures (ie: raise an interrupt on the current Action, which would catch interrupts and return). I'm happy to submit a patch to that effect given some guidance on which if either is a good strategy. > My use-case is a REPL-like utility that can run each expression the > user types in a separate thread, and can kill off threads that are > misbehaving or not terminating. If you want to cover Non-interruptible Blocking then some additional techniques are required: http://book.javanb.com/java-concurrency-in-Practice/ch07lev1sec1.html It seems to me that canceling a thread in Java is quite a topic! So apologies if my suggestion is too trivial or misses the point. Regards, Tim. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---