English 中文(简体)
Google Javascript v8 - multithreading
原标题:

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
问题回答

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.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签