Creating different v8 contexts that are clones of another
Asked Answered
B

1

6

Using Google's v8 c++ library, I am wanting to create a context where I have several templates, variables, and globals defined and ready for use by several places in code that may run on different threads, each with its own isolate, where they should also each have their own local copy of the context so that any changes to the global variables in one thread will not impact the others.

I can do this by explicitly setting up all my templates, variables, and globals each and every time I want a new context, but I am wondering if there is a more efficient way. Assume that I already have a global v8::Isolate pointer and v8::Persistent that represent the master state. What do I then need to do, if I want to create a brand new isolate in its own thread,and make a new context that is essentially a clone of the master? I know I can wrap a mutex around accesses to the master to ensure that different threads do not access it at the same time if necessary. I just don't know how to efficiently copy information that was made in one isolate to another without recreating its entire contents from scratch.

Brushoff answered 13/8, 2014 at 19:47 Comment(0)
D
2

You cannot share objects between Isolates. From here

Isolate represents an isolated instance of the V8 engine. V8 isolates have completely separate states. Objects from one isolate must not be used in other isolates. The embedder can create multiple isolates and use them in parallel in multiple threads. An isolate can be entered by at most one thread at any given time. The Locker/Unlocker API must be used to synchronize.

Danaides answered 21/10, 2015 at 21:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.