Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JS_SetHeartbeatCallback in single-thread embedded JS

28 views
Skip to first unread message

sten.g...@gmail.com

unread,
Jul 2, 2012, 4:51:28 AM7/2/12
to
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

Wes Garland

unread,
Jul 2, 2012, 7:22:21 AM7/2/12
to sten.g...@gmail.com, dev-tech-...@lists.mozilla.org
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

sten.g...@gmail.com

unread,
Jul 2, 2012, 8:03:37 AM7/2/12
to sten.g...@gmail.com, dev-tech-...@lists.mozilla.org
Yep, alarm() solved my problem. Thank you!
0 new messages