Subj : Re: JS_THREADSAFE / assertion failed on rt->gcRunning To : sebastien maraux From : Brendan Eich Date : Thu Mar 03 2005 02:43 pm sebastien maraux wrote: > When I run my program, it crashes after a few seconds, on an assertion > failed to know if gc is running: > JS_ASSERT(!rt->gcRunning); You have written a finalizer that attempts to allocate a new GC-thing. Don't do that. > I have read following post, where you can read that building js with > JS_THREADSAFE and NSPR or a small replacement for it could fix my > problem : > > http://groups.google.ca/groups?hl=en&lr=&ie=UTF-8&selm=7be32359.0403171719.2ef8666%40posting.google.com > > However, I don't understand why js is built as multithreaded but > without this tag in its default configuration, if it's unsafe. I don't know what you mean. SpiderMonkey can be built without JS_THREADSAFE for use in single-threaded embeddings, and with JS_THREADSAFE for multi-threaded embeddings -- in the latter case you want NSPR or a workalike (I am not sure that the post you link to above supplies a complete workalike). > Moreover latest NSPR static binaries are not valid on the ftp (I can > link js to dll ones, but not static ones), and I don't want additional > dlls in my project. Pull the source from cvs.mozilla.org and build it yourself. > I also mention that however my environement is multithreaded, I am > using js only in a single thread of my program but it still crashes. Then why are you defining JS_THREADSAFE? Oh, you're saying that the builds we put up define it? Those must be the library builds used with the Mozilla suite, e.g. libmozjs.so on Linux. Again you should built it yourself to suit your own requirements. We provide builds as a convenience for developers, but we can't manage a bunch of different configurations that meet all needs. > Also, is there some detailed doc on how to use JS_BeginRequest / > JS_EndRequest other than js-c api reference ? I understand that it > should be placed to bracket maximum non blocking chunk of code, but > for example if I set members of an object from another , without > knowing their number in advance, can it be considered as non blocking > (or short enough) calls ? Or should I test for array size before > calling JS_BeginRequest. If their is too many elements, must I break > it in several smaller calls (this could be an issue as I have to > handle a lot of different arrays types). It depends on how long the loop you've written could run. If you're worried, maybe using an unsigned index and testing (i % 1024) == 0 or similar to call JS_YieldRequest(cx) would be good (I made up 1024, you should pick a better number). > I'll now try older versions of NSPR, but I am afraid that it will > greatly increase my code footprint to link with NSP lib. Use a static libnspr4.a library you build yourself, and ld shouldn't link more than you need. /be .