Creating different v8 contexts that are clones of another

Using Google v8 C ++ library I want to create a context in which I have several templates, variables and globals defined and ready to use by several places of code that can be executed on different threads, each with its own isolate where they are also must have their own local copy of the context so that any changes to global variables in one thread do not affect others.

I can do this by explicitly setting all my templates, variables and globals every time I want a new context, but I'm wondering if there is a more efficient way. Suppose I already have a global pointer v8 :: Isolate and v8 :: Persistent that represent the state of the master. What then do I need to do if I want to create a completely new isolation in my thread and create a new context that is essentially a clone of the master? I know I can wrap a mutex around master access to ensure that different threads don't access it at the same time if needed. I just don't know how to efficiently copy information that was done in one isolate without re-creating the entire content from scratch.

+3


source to share


1 answer


You cannot share objects between Isolates. From here



The insulation is an isolated instance of the V8 engine. V8 isolates have completely separate states. Objects from one isolate should not be used in other isolates. Embedding can create multiple isolates and use them in parallel across multiple threads. Isolation can be introduced by no more than one thread at any given time. To sync, you need to use the Locker / Unlocker API.

+2


source







All Articles