Subj : JavaScript/XPCOM and mutithreading.... To : netscape.public.mozilla.xpcom,netscape.public.mozilla.jseng From : jmp Date : Thu Dec 02 2004 12:37 pm Hi, Well, I initially assumed that Javascript is not built-in with much thread-safe stuff in it, but was wondering where the limit of multithreading was. The JS_SetContextThread( cx ) lead me to believe that only 1 cx can be executed at a time: fine! So I was wondering: Could I have: compile of the script on thread1 then using JS_SetContextThread( cx ), get the thread to execute on thread2 ? and what do I do with the nsIJSContextStack? or will I need to create a nsIJSThreadContextStack per thread ? actually, what nsIJSContextStack is all about exactly anyway thread 1: m_cx = JS_NewContext(m_rt, 8192); ... /* All the cooking for JS engine/principal/gloabl object...etc... */ ... JS_CompileUCScriptForPrincipals(m_cx, m_glob, jsp , (jschar*)mScripts.get() , mScripts.Length() , "" , 0); JS_ClearContextThread( m_cx ); then a bit later, thread 2: JS_SetContextThread( m_cx ); JS_ExecuteScript(m_cx, m_glob, m_script, &result); JS_ClearContextThread( m_cx ); And what about other objects/operations? are the globals defined in the javascript available accross threads ? thanks .