Subj : rooting objects across threads To : netscape.public.mozilla.jseng From : zakalawe@mac.com (James Turner) Date : Sun Aug 03 2003 05:56 am I've recently begun the process of add threading to my JS embedding application, and need a few things clarified. I'll break things into a few seperate posts to keep the subjects clearer. Firstly, what is the relationship between contexts and rooting objects to avoid garbage collection? Essentially, I am doing this: Thread 1: (main thread) jsval myVal = ..... convert some data into JS ... // should JS_AddRoot myVal here? thread_safe_queue.add(myVal); Thread 2: (worker thread) while ( 1 ) { // next line will block if the queue is empty jsval workData = thread_safe_queue.next(); JS_BeginRequest(); ... do some long, blocky work with the workData .... JS_EndRequest() JS_MaybeGC(); } So, my obvious worry is, what do need to do to stop items waiting in my work queue being garbage collected before they're processed? It looks froms the docs as if JS_AddRoot is context specific, but obviously my main thread and worker threads each have their own context. I saw a reference to JS_LockGCThingRT, which only takes a JSRuntime* instead of a context, perhaps this is what I should be using? Any suggestions appreciated. (And as an aside, is my use of [begin|end]Request, and maybeGC roughly correct?) Many thanks, James .