Subj : Re: JS_DestroyContext() access violation.. To : njaguar From : Brendan Eich Date : Thu Feb 27 2003 10:39 pm > > >The application is multi-threaded, each script runs on it's own >thread, but a single context never has more than one thread.. > By definition, a context cannot be used by more than one thread at a time, in any embedding. > I don't >think this is a case of being multithreaded, > It is. You must compile with JS_THREADSAFE defined, use NSPR for locks and condition variables, and use JS_BeginRequest (http://www.mozilla.org/js/spidermonkey/apidoc/gen/complete.html#JS_BeginRequest) and JS_EndRequest around non-blocking batches of JS API calls. If a native method or getter/setter needs to block, it must use JS_SuspendRequest before blocking and JS_ResumeRequest after. See the API docs, and many posts in this newsgroup, e.g. news://news.mozilla.org:119/36EE7ACF.341732BD@netscape.com, news://news.mozilla.org:119/396E1477.82DA4C33@meer.net, news://news.mozilla.org:119/3B1D26E4.F3180F7A@meer.net, news://news.mozilla.org:119/3BF4395C.9090408@meer.net. Don't forget GC safety along with thread safety: http://www.mozilla.org/js/spidermonkey/gctips.html. > but I really don't know.. >It's quite odd, and happens somewhat randomly (and hasn't for quite >some time actually...) It's almost like the Context isn't ready to be >destroyed or something, or perhaps my js32.dll is ancient, and needs >to be updated.. ;) > You're playing with fire if you use a thread-unsafe JS engine in multiple threads. One context per thread at a time is the minimum, but it doesn't protect you -- you need JS_THREADSAFE and the request model too. /be .