Subj : Re: multithread question To : Kumar Iyengar From : Brendan Eich Date : Tue May 11 2004 05:47 pm Kumar Iyengar wrote: > I am in the process of evaluating Spidermonkey and have written a prototype > that embeds Spidermonkey in our application. I have followed the rules(as > far as i can tell) of multithreadedness as Spidermonkey recommends: > *) Compile the library with JS_THREADSAFE, > *) link with the libnspr4.lib file I assume you have turned off DEBUG and turned on compiler optimizations. > *) In code call BeginRequest and EndRequest in all places where there might > be a potential block. That's wrong. The rule is to call JS_SuspendRequest before blocking, and JS_ResumeRequest after. > Also, i have gone with the model currently where i have a Runtime for each > thread. I know i can go with one Runtime but i have chosen this just for > now. > > I have a script that adds 2 numbers. To get the numbers it makes a native > call and another native call to set the result of the addition. In both the > native calls, the work is done between the BeginRequest and EndRequest. That's wrong. The request begin and end should be at the highest level of your embedding application, when it is calling into the JS API. You should not be calling request APIs within native methods except when blocking (or taking a long time while not requiring unrooted GC-things to be protected). /be .