[Haskell-cafe] Need help with very simple C++ FFI call

Sven Panne svenpanne at gmail.com
Tue Nov 19 19:02:22 UTC 2013

2013/11/19 Yuras Shumovich <shumovichy at gmail.com>:
> [...] but I see only one not trivial difference with my code. I'm
> creating isolate manually, and you are using the default one. Check that
> Isolate::GetCurrent() returns anything. I can imaging that your code is
> running in unbound green thread, or it is bound to OS thread other then
> the main one. v8 use thread local storage, that can be the issue.

Yes, v8 uses TLS to store the current Isolate (= VM instance) for
historical reasons, and if you want to use the default Isolate
(created even before main() is entered) things get tricky if you are
not using it from the main thread. Furthermore, if you use an Isolate
from various threads (sequentially, re-entry is not allowed) you have
to use v8's Locker to tell v8 what's happening. Isolate::Scope has to
be used to tell v8 when you are switching between several Isolates in
a single thread.

This is all sub-optimal (<- huge understatement) and we regret the
introduction of TLS in v8 every single day, it is a constant source of
bugs, confusion and complexity. Having said that, we are currently in
the process of removing TLS and make the Isolate very explicit in v8's
API. But this is easier said than done, given all the various complex
embedders v8 has (Chrome, node.js, ...). In a bright future, v8 uses
no TLS, all Isolates are explicit, there is no default Isolate and no
"current Isolate", and Isolate::Scope and Locker are merged. Until
then things are a bit tricky, but you can make your life easier by
building a debug version of v8, which has tons of assertions, making
stuff like a NULL Isolate blindingly obvious.

Choosing a combination of 2 multi-threaded runtimes for learning
purposes has a slightly masochistic touch... ;-)

More information about the Haskell-Cafe mailing list