JS_SetHeartbeatCallback in single-thread embedded JS

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

JS_SetHeartbeatCallback in single-thread embedded JS

Sten Gruener
Hello,

Spidermonkey 1.8.5
I am a single-thread embedder and I need to break up the infinite loops in the embedded JavaScript. As I understood, I need to use JS_SetHeartbeatCallback function, however it is not visible due to JS_THREADSAFE, that can not be disabled.

Is there a way out?

Regards
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|

Re: JS_SetHeartbeatCallback in single-thread embedded JS

Wes Garland
I've never used them, but the heartbeat functions are supposed to be
invisible when JS_THREADSAFE.

It sounds like you are building a thread-safe JSAPI for a single-threaded
environment. This is fine, and will likely be the only option in future
JSAPIs.

My recommendation is to use a second "watchdog" thread to keep an eye on
your JS-running thread.  If JSAPI does not return fast enough, you can
trigger an operation callback which then returns JS_FALSE and aborts the
execution of your JS code.

If you are in an environment where the compiler does not support threads
(e.g. embedded systems), you can do something similar with timers or
alarm().

Wes

--
Wesley W. Garland
Director, Product Development
PageMail, Inc.
+1 613 542 2787 x 102
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|

Re: JS_SetHeartbeatCallback in single-thread embedded JS

Sten Gruener
In reply to this post by Sten Gruener
Yep, alarm() solved my problem. Thank you!

Am Montag, 2. Juli 2012 13:22:21 UTC+2 schrieb Wes Garland:

> I've never used them, but the heartbeat functions are supposed to be
> invisible when JS_THREADSAFE.
>
> It sounds like you are building a thread-safe JSAPI for a single-threaded
> environment. This is fine, and will likely be the only option in future
> JSAPIs.
>
> My recommendation is to use a second "watchdog" thread to keep an eye on
> your JS-running thread.  If JSAPI does not return fast enough, you can
> trigger an operation callback which then returns JS_FALSE and aborts the
> execution of your JS code.
>
> If you are in an environment where the compiler does not support threads
> (e.g. embedded systems), you can do something similar with timers or
> alarm().
>
> Wes
>
> --
> Wesley W. Garland
> Director, Product Development
> PageMail, Inc.
> +1 613 542 2787 x 102

_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine