假设我有以下代码
bool run (void)
{
HandleScope hande_scope;
Handle<String> source;
Local<Script> script;
Persistent<Context> context;
context = Context::New();
Context::Scope context_scope(context);
script = Script::Compile("var a = 1; var b = 2;");
Local<Value> result = script->Run();
if (result.IsEmpty())
return false;
else
return true;
}
确实不能使用多个线程执行此代码吗?似乎HandleScope
不是为多线程应用程序设计的。我可以使用v8::Locker
andv8::Unlocker
方法,但这总是会给我执行跟踪,如下所示:
t1: a = 1
t1: b = 2
t2: a = 1
t2: b = 2
我希望有人能给我一个关于让这个代码多线程的提示,以便可能的执行跟踪可以像这样:
t1: a = 1
t2: a = 1
t1: b = 2
t2: b = 2