How to use v8 in a stream?

I am trying to use v8 from C ++ inside a thread that is not a main thread. There is no multithreading compared to v8, all v8 objects are created and destroyed inside this thread. Nothing works in parallel, nothing is divided. When I run my program from the main thread, everything works fine. When I have v8 stuff in another thread, I get a segmentation error when I create v8 :: HandleScope.

I cannot find any useful documentation on how streaming processing is actually addressed using v8. When searching often, the prompt “Use isolates and cabinets” appears, but I can’t find examples of how to do this. There is this doc API on v8 :: Isolate, but nothing on this page tells me if I need them in my particular case (I do not use memory or do parallel). Documents on v8 :: Locker () do not even have information about what the class is for. The included samples in the project are also not related to any of them.

So my questions are ...

  • Do I need to use isolates and / or cabinets here?
  • Can I get a minimal example of how to use them? Even pseudo code or something would be really useful
+7
source share
1 answer

You need V8 :: Locker in methods that will work with context when calling HandleScope. https://github.com/jasondelponte/go-v8/blob/master/src/v8context.cc#L41 is an example of how I use locker with v8. In this example, it is used with multiple threads, but I believe that the rule applies to individual threads as well.

Isolates are only needed when you need multiple instances of v8 in parallel.

https://groups.google.com/forum/?fromgroups=#!topic/v8-users/FXpeTYuAqKI This is an old thread that I found a little back that helped me solve my library failure problem as soon as the local variable HandleScope was created.

+2
source