Is it possible to create multiple isolates in one thread?

43 views
Skip to first unread message

Cooper Kuo

unread,
Dec 19, 2019, 2:25:46 AM12/19/19
to v8-users
Hi, I am working out of a v8 embedder, I want to use multiple isolates at the same time, and these isolates should run in one thread, because there are some thrid-party framework api should be called inside main thread.

In v8 official reference about v8::Isolate:

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.

It is apparently that I can use one isolate in one thread, even one isolate in multiple threads, but there is no description about "multiple isolates in one thread".

Jakob Kummerow

unread,
Dec 19, 2019, 4:53:24 AM12/19/19
to v8-users
Sure, a single thread can use as many Isolates as it wants. Most V8 API functions take an Isolate or a Context (which implies an Isolate) parameter to facilitate this.

Things to keep in mind:
- creating an Isolate is somewhat expensive, so creating millions of short-lived Isolates is not great for performance. (Having dozens or even hundreds of long-lived Isolates is perfectly fine.)
- objects (including functions, contexts, ...) are tied to the Isolate they were created in. They can't be moved to, or executed in, or accessed from another Isolate.


--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/ace604a3-1d78-4162-9e24-e161bb5cc9f6%40googlegroups.com.
Message has been deleted

Cooper Kuo

unread,
Dec 19, 2019, 5:08:01 AM12/19/19
to v8-users
Thank you Jakob, now I know it is fine to use multiple isolate in one thread. :-)

To unsubscribe from this group and stop receiving emails from it, send an email to v8-u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages