Subj : Re: Sharing javascript runtimes? To : Brian From : Brendan Eich Date : Tue Oct 07 2003 11:51 am Brian wrote: >Is there any way for multiple, separate apps to use the same >spidermonkey runtime, but with it's own context? > >For instance, lets say I have 5 processes running on the same machine, >simultaneously. Is there any way to see if the runtime has been >created, and get a new context to run in the runtime? > > Not in the JS API. Why do you want to do this? >Or, is it necessary that each process has it's own runtime? > > Practically speaking, that's necessary. >Or, is it a combination between the two? Could I use inter-process >communication to tell other processes which runtime to use? > > How would they access it? Using some kind of inter-process shared memory? Or using proxies and RPC? How would you arrange to do distributed garbage collection? >Ideally, I would want to be able to have a process do something like: > >if(!attach_existing_runtime()) > create_new_runtime() > >Would this save resources the way I would expect it to? > Not really. If you're doing this for some kind of memory savings, you are optimizing prematurely. If you are doing this to share objects among processes, then not only will there be some savings (small, probably), but you are designing a system that requires such sharing as part of its programming model. You'll need locking (mutual exclusion) and other things (condition variables?) too, which will make for a complex, multithreaded model. Why not use threads in one process? They share address space by definition. Give each thread its own context. You'll still need to consider how JS programmers (script authors, not necessarily expert programmers) will manage synchronization and protect any critical sections or invariants in shared objects. /be .