Hi, I have just searched for a week and I'm unable to make my code work. So
I decide to post my problem, hope someone can help me:
My application is multi-threaded, and I want one and only one isolate in my
application (just 1 v8 virtual machine, and it can be init - shutdown, and
init again with refreshed variables), its lifecycle is as follow:
- My global variables:
v8::Isolate *g_Isolate; // I get the isolate when application start, and
lock this isolate whenever a thread call my method
v8::Persistent<v8::Context> g_Context; // I want to cache a global
persistent context, is this right?
v8::Persistent<v8::ObjectTemplate> g_FieldTpl; // This is a global template
for me to creating object and wrap it by v8 object, as sample process.cc
- Engine start: I want to initialize V8 engine here, setup global template
and cache global isolate like this:
g_Isolate = v8::Isolate::GetCurrent();
if(!g_Isolate) {
g_Isolate = v8::Isolate::New();
g_Isolate->Enter();
}
v8::HandleScope handle_scope(g_Isolate);
v8::Handle<v8::Context> tmpContext = createContext(g_Isolate);
g_Context.Reset(g_Isolate, tmpContext);
tmpContext->Enter();
if (g_FieldTpl.IsEmpty()) {
v8::Handle<v8::ObjectTemplate> raw_template = createTemplate(g_Isolate);
g_FieldTpl.Reset(g_Isolate, raw_template);
}
- Engine shutdown:
g_FieldTpl.Dispose(g_Isolate);
g_Context.Dispose(g_Isolate);
g_Isolate->Exit();
g_Isolate->Dispose();
v8::V8::Dispose();
g_Isolate = NULL;
- Thread access: I always start with:
v8::Locker locker(g_Isolate);
v8::Isolate::Scope isolate_scope(g_Isolate);
v8::HandleScope handle_scope(g_Isolate);
and don't create any other context (I just want only one context throughout
my engine lifecycle)
Currently, I always have crashes when shutdown, if I comment the line:
v8::V8::Dispose, application won't crash but when I start engine again, it
crashes.
What I want, is ability to start v8 (or init, or something), call method or
receive callback from any thread and can be totally shutdown at anytime. I
can call method/receive callback normally, but currently I have problem
with initialization/destruction. May I miss something? Or anything is wrong?
Sorry for my bad English, thanks everybody for reading!
--
--
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/groups/opt_out.