Is it safe to unlock V8 in v8 callback and enter V8 from another thread ?

200 views
Skip to first unread message

Srinivas

unread,
Sep 4, 2014, 12:01:59 AM9/4/14
to v8-u...@googlegroups.com
We are using V8 as our Javascript engine. As part of our project design , we need to execute the JS code from multiple threads. As documentation says, V8 isolate is not thread safe, we are wrapping the V8 entry points with Locker object so that only one thread can access the V8 api at any point of time but this making the other threads to wait for longer time if the thread-1 is doing some long pending operation. Now we want to make the thread-1 release the lock using Unlocker api when ever it is doing some non-v8 operation so that other threads can enter. But this is not working for us as V8 is crashing when we trying to create object using Object::New() api from thread-2.

Here is the code level visualization,

jsFun code snippet
================
function myfun(obj){
    nativeAnimation(); // this is native callback
}

native function
=============
void nativeAnimation(Args){

....
 Unlocker unlock;
 gameengine->animate(); //while it unlocks and another thread enter v8 but crashes whenever creating Object::New()
.....

}


Thread-1
=======
Locker
V8 api {
   Handle<Object> obj = Object::New();  //It works
   jsFun->Call(obj);    // this js function calls "nativeAnimation" api which is a callback to to game engine and this spends some time in engine.
}


Thread-2
========
Locker
V8 api {
   Handle<Object> obj = Object::New();  //It crashes here
}


Can Some one help me to understand whether it is possible to Unlock while in the middle of some JS function execution and entered by another thread.?
 

Sven Panne

unread,
Sep 4, 2014, 2:59:52 AM9/4/14
to v8-u...@googlegroups.com
On Thu, Sep 4, 2014 at 6:01 AM, Srinivas <sreeni...@gmail.com> wrote:
[...] Can Some one help me to understand whether it is possible to Unlock while in the middle of some JS function execution and entered by another thread.?


Without any more details it's hard to tell what's wrong with your code. The best route for you would probably be building a debug version of v8 to get a stack trace where exactly things crash.
Reply all
Reply to author
Forward
0 new messages