I'm still somewhat new to embedded v8 programming with C++, so it's
possible that I might be doing things in less than an optimal way here, but
how I've been using v8 so far is that whenever I want to use it, I am
using some (possibly not wholly necessary) boilerplate code kind of like
the following:
v8::Isolate isolate = getGlobalsolate();
{
v8::Locker locker(isolate);
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
v8::Handle<v8::Context> context = getGlobalContext();
v8::Context::Scope context_scope(context);
....
do stuff
....
}
Of course, this means that I am locking the isolate for as long the entire
block is running, which would prevent another thread from using the isolate
at the same time, but more importantly, it would also prevent another
thread from doing absolutely anything that might need the global v8 context
until the block is finished. need to use single v8::isolate and
persistent context because there are global variables that absolutely all
the other code will need to see, so if any task manipulates data in the v8
context's global variables, it must be visible to every other place in the
program that uses javascript.
Anyways, there's one function that I'm wanting to do some work on which
currently contains three of these boilerplates, and I'm hoping to
streamline it if I can.
The first block compiles some user-supplied function definitions that will
be used later.
The second block consists of a sometimes very lengthy process which reads
data from a potentially very long file putting each result into a
v8::Handle<v8::Value>, which it will then pass to a user-supplied function
(compiled in the first block) to process. It collates the results from
the user-defined function into assorted v8::Persistent<v8::Array>.
The final block of code passes each persistent array accumulated by the
above block into a second user defined function that was compiled in the
first block.
The first problem I have with this monolithic function is the time that the
second block takes to complete, since it has locked my global isolate for
the entire time it executes, and I am not entirely sure that is necessary.
As an aside, I know that I could also encapsulate all three blocks of code
into one and just have a single instance of the boilerplate code, but
because I am wanting other threads to maybe use the same isolate, that
would make the problem I am wanting to mitigate even worse.
What I am actually hoping to do with this second block of code is split
this single task into several threads (C++11 std::threads,ideally. but if
there is a particular type of v8 thread I can use, I am amenable to that,
although I will need to learn the details of using it), each thread reading
only a small portion of the file, and instead of putting a v8::Locker on
the entire block of code, I am hoping to only have to put such a Locker
around the critical portions of the code where it is absolutely required.
Finally I'm hoping to streamline my boilerplate code everywhere, so that it
doesn't contain any unnecessary cruft that I can get away with initializing
only once.
The other thing that I'd like to do is augment the third block to also be
multithreaded... instead of calling the user defined function with each
array one after the other, I would instead like to process the different
arrays in parallel, and I'm not sure how to achieve this with v8.
Any assistance or help would be greatly appreciated.
Thanks in advance
Mark
--
--
v8-users mailing list
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.