Google Javascript v8 - multithreading - Stack Overflow

Suppose I have the following piece of codebool run (void){HandleScope hande_scope;Handle<String>

Suppose I have the following piece of code

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;

}

Is it true that one cannot execute this code using multiple threads? It seems like HandleScope is not designed to be used in multithreaded applications. I can use the v8::Locker and v8::Unlocker methodes but that would always give me execution traces as this:

t1: a = 1
t1: b = 2

t2: a = 1
t2: b = 2

I hope someone can give me a hint on getting this code multithreaded so that a possible execution trace could like this:

t1: a = 1
t2: a = 1

t1: b = 2
t2: b = 2

Suppose I have the following piece of code

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;

}

Is it true that one cannot execute this code using multiple threads? It seems like HandleScope is not designed to be used in multithreaded applications. I can use the v8::Locker and v8::Unlocker methodes but that would always give me execution traces as this:

t1: a = 1
t1: b = 2

t2: a = 1
t2: b = 2

I hope someone can give me a hint on getting this code multithreaded so that a possible execution trace could like this:

t1: a = 1
t2: a = 1

t1: b = 2
t2: b = 2
Share Improve this question edited Dec 13, 2017 at 20:44 ROMANIA_engineer 56.8k30 gold badges210 silver badges205 bronze badges asked May 10, 2010 at 12:31 willemwillem
Add a ment  | 

2 Answers 2

Reset to default 2

According to v8 issue 510, a feature called "Isolates" was added to the trunk some months back. This should allow multiple (non-interacting) instances of v8 in a single process.

Look at this post. The v8 engine has a Locker class, that lets you preempt your code. With this you can use multiple threads.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744715097a4589569.html

相关推荐

  • Google Javascript v8 - multithreading - Stack Overflow

    Suppose I have the following piece of codebool run (void){HandleScope hande_scope;Handle<String>

    16小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信