Am 11.01.2014 18:16, schrieb Till Schneidereit: > On Sat, Jan 11, 2014 at 4:52 PM, Andreas Schlegel > <schlegel.andr...@gmail.com <mailto:schlegel.andr...@gmail.com>> wrote: > > > Contexts and threads don't have much to do with each other. If you > > ignore a couple of things, a JSRuntime is always in a single > thread and > > all JSContexts of that runtime are in the same thread. If you have > > multiple threads, you need a runtime for each, and each runtime will > > use one or more of its own JSContexts. > Ok, thats new for me, because I read the following from > JSAPI_basics-Dokumentation: > "There is a close association between contexts and threads. Simple, > single-threaded applications can use a single context for everything. > But each context can only do one thing at a time, so in a > multithreaded > application, only one thread at a time should use any given context. > Such an application typically has one context per thread." > > > Yeah, so our documentation is sometimes ... lacking. Or outdated. Or, > most frequently, both. > > SpiderMonkey used to be fully multi-threaded and was able to execute > multiple JS scripts in parallel in the same runtime. Quite a while > ago, that capability was removed, because it became a maintenance > nightmare and hindered cleanup and progess. > > I have just removed the section from the documentation: afaict, it's > entirely false and doesn't even need replacement. > > > But if each Thread has its own runtime, how is it possible to access > variables from different threads? Because the documentation says that > each "/runtime/, is the space in which the JavaScript variables, > objects, scripts, and contexts used by your application are > allocated". > > > It's not possible. Objects have to be cloned or transferred from one > runtime to the other. That's what happens when postMessage is used to > send data to or from a DOM Worker. > > > >> If I have a multi-threaded application and the object has an other > >> Context as the default is this correct or not? If not how can I > get the > >> correct? > > > Regardless of the threading stuff, objects don't belong to contexts at > all. They belong to compartments and can only be accessed if that > compartment has been entered. To refer to objects from other > compartments, a cross-compartment wrapper has to be created. I would > recommend dealing with that after your changes work within a single > global object. Can you explain me a little bit? I understand that the compartments are used to create multiple memory heaps for increasing perf of the garbage collector and the wrappers are used to touch objects from another compartment. But I don't understand the direct relation to my work. I need the Context to create RootedValues/Objects and for calling other functions which needs the context. I found only a function which gives me the default context over the runtime of an object, but the object's don't belong to the context :-). It's a little bit confusing to me.
_______________________________________________ dev-tech-js-engine-internals mailing list dev-tech-js-engine-internals@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals