Subj : Re: SpiderMonkey threading issues To : Sean Proctor From : Brendan Eich Date : Wed Mar 09 2005 02:54 pm Sean Proctor wrote: > Hello, > > After reading a lot of prior posts, it seems like what I am trying to do > should work. So I think that I am missing something. If it doesn't work, how exactly does it fail? > I want to run a script from within one thread. In that script I am > defining JS functions and passing them to a native (C) function. Those > functions will be called under certain external conditions from another > thread. So you're defining these functions as properties of a global object in one thread, and calling them in another? Do you take care to use that global object from at most one thread at a time? > The things I'm unsure of are: Do I need to use NSPR to create my threads? If you use NSPR locking (PR_Lock, PR_WaitCondVar, etc.), then you need either to create threads using NSPR (PR_CreateThread), or call JS threadsafe code that calls NSPR locking primitives from a thread to which NSPR can automatically attach. Cc'ing wtc, who can remind us of the restrictions, if any on such a thread. > Right now I am using glib for that. Is there anything special I need to do > with objects to use them in a different context from the one they were > created in? Objects, no. An object is allocated from a runtime-wide (typically "global" or process-wide) GC heap -- by runtime I mean JSRuntime. Again, though, you generally don't want scripts concurrently using the same global or other scope objects, because authors have no way to synchronize data access (nor should they in general). /be .