On Thu, Apr 21, 2011 at 1:41 PM, Stephan Beal <[email protected]> wrote:
> On Thu, Apr 21, 2011 at 12:58 PM, Matthias Ernst <[email protected]>wrote: > >> Let's turn the question around. How in the world does SpiderMonkey support >> multi-threading? How is it specified? Did they invent a memory-model for JS? >> > > They have some magical macro called JS_THREADSAFE which, when set, enables > threading support. > > The SpiderMonkey readme says: > > ---------- > <a NAME="Build"></a>Build conventions (standalone JS engine and shell) > (OUT OF DATE!)</h2> > These build directions refer only to building the standalone JavaScript > engine and shell. To build within the browser, refer to the <a > href="http://www.mozilla.org/build/">build > directions</a> on the mozilla.org website. > <p>By default, all platforms build a version of the JS engine that is > <i>not</i> > threadsafe. If you require thread-safety, you must also populate > the <tt>mozilla/dist</tt> directory with <a href=" > http://www.mozilla.org/projects/nspr/reference/html/" > >NSPR</a> > headers and libraries. (NSPR implements a portable threading library, > among other things. The source is downloadable via <a href=" > http://www.mozilla.org/cvs.html">CVS</a> > from <tt><a href="http://lxr.mozilla.org/mozilla/source/nsprpub > ">mozilla/nsprpub</a></tt>.) > Next, you must define <tt>JS_THREADSAFE</tt> when building the JS engine, > either on the command-line (gmake/nmake) or in a universal header file. > ---------- > > > Specific functions mention specific serialization requirements when > JS_THREADSAFE is set, but beyond that it's anyone's guess. > https://developer.mozilla.org/en/JS_THREADSAFE *JS_THREADSAFE* is a compile-time option that enables support for running multiple threads of JavaScript code concurrently *as long as no objects or strings are shared between them*. We have recently made major changes to this feature. Until recently, sharing objects among threads would mostly work, although scripts could easily make it crash. We have now completely removed that feature. *Each thread that uses the JavaScript engine must essentially operate in a totally separate region of memory.* https://developer.mozilla.org/en/SpiderMonkey/JSAPI_Reference/JSRuntime *Only one thread may use a JSContext at a time*. I don't see how this would be more permissive than V8's threading rules. Multiple isolates allow for concurrent execution of JS in isolated regions. I suspect you might get lucky in SpiderMonkey if you share read-only objects but the docs clearly prohibit it. Matthias > > -- > ----- stephan beal > http://wanderinghorse.net/home/stephan/ > > -- > v8-users mailing list > [email protected] > http://groups.google.com/group/v8-users > -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
