easieste wrote: > Working in Common Lisp on the JVM, I wish to emulate the semantics of > a typical thread library (there is nothing in ANSI about such > interfaces, they vary widely) > > (WITH-TIMEOUT timeout &REST body) > > which runs an arbitrary BODY of code on a new thread until TIMEOUT > seconds have elapsed, upon which the thread is terminated > unceremoniously. > > The typical way to emulate the dangerous java.lang.Thread.stop() type > interfaces to run Java threads on a heartbeat loop which terminates if > a condition is met (like a global static variable of primitive type > boolean turns false), but I am unable to do this for arbitrary code > where I don't know where the "safe" loops. Short of instrumenting the > Java bytecode associated with the invocation of BODY with synthetic > handlers, does someone have a clever hack to get the JVM to emulate > interruptible threads?
FWIW, in JRuby we checkpoint, and we hate having to do it. Essentially we set up heartbeat checks at the same points where normal Ruby calls into its thread scheduler. That gives us roughly the same granularity of events, and so we can emulate interruptible threads. And in general, performs is impacted only slightly by this overhead: fib(30) with hearbeats (default): 0.836000 0.000000 0.836000 ( 0.837000) 0.409000 0.000000 0.409000 ( 0.410000) 0.408000 0.000000 0.408000 ( 0.409000) 0.397000 0.000000 0.397000 ( 0.397000) 0.447000 0.000000 0.447000 ( 0.448000) fib(30) with hearbeats disabled (-J-Djruby.compile.threadless=true): 0.927000 0.000000 0.927000 ( 0.926000) 0.407000 0.000000 0.407000 ( 0.408000) 0.409000 0.000000 0.409000 ( 0.409000) 0.402000 0.000000 0.402000 ( 0.403000) 0.499000 0.000000 0.499000 ( 0.500000) Of course we're always looking for a better way; it's really unfortunate to have to do this. I've been lobbying the Ruby community to eliminate such idioms, but it's a very slow process. - Charlie --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "JVM Languages" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/jvm-languages?hl=en -~----------~----~----~----~------~----~------~--~---
