Can a local data store be tampered with?

I feel a little weird.

I have a great application that has the Google V8 JavaScript engine. Some calls go to the V8 engine in the user interface thread. To be pleasant for the user, as everyone recommends, some long operations are launched in a separate thread without having to hang up the user interface thread. However, these lengthy operations also make calls to the V8 JavaScript engine. Thus, multiple threads are accessing V8.

The thing is, V8 seems to be using local thread storage. This seems to make my app a random blast. It is definitely in the class "How has this been possible so far?" mistakes.

Without significant re-archiving of my application, I suggest an ugly, ugly, awful super-hack: can I get V8 to assume that it is running on a different thread?

In other words, the first time I call V8, I take a note on the stream. Then, for all the other V8 calls, I somehow cheat the thread, so the local thread store works / no matter which thread depends on the thread.

Can this be done? Will this work? Am I so stupid that I even consider such a tricky hack?

+3
source share
2 answers

You don't have to fake anything. Instead, you should tell V8 that you are trying to use it from another thread.

V8 3.2 - v8::Locker , V8 . V8, , TLS. . http://code.google.com/p/v8/source/browse/branches/3.1/include/v8.h#3189

3.2 V8 . , V8 , API. v8::Locker, . , v8::Locker v8::Isolate::Enter/v8::Isolate::Exit v8::Isolate::Scope. . http://code.google.com/p/v8/source/browse/trunk/include/v8.h#3510

, : v8::Locker, V8 .

+18

, . VE, v8 . , .

, , , JS-. , ,

  • v8::Isolate. , ( ) ( ).

  • , v8 ( ), ( v8::Isolate::Scope)

  • 'v8:: Locker'.

, , :

class SessionLock {
private:
    v8::Isolate::Scope scope;
    v8::Locker lock;

public:
    SessionLock() : scope(getSessionIsolate()), lock(getSessionIsolate()) {}
};
+1

All Articles