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

Thiago Padilha tpadilha84 at gmail.com
Tue Nov 19 17:13:04 UTC 2013


On Tue, Nov 19, 2013 at 1:50 PM, Yuras Shumovich <shumovichy at gmail.com> wrote:
>
> Ok, then I don't see anything obviously wrong.
>
> I was embeding v8 into haskell project few months ago, and almost the
> same code works for me.
>
> I don't have v8 installed right now, so I can't try your code at the
> moment, 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.

Yuras, you are correct now :)

I've replaced the first line by these:

     Isolate* isolate = Isolate::New();
    // Sets this isolate as the entered one for the current thread
    isolate->Enter();

And the example worked as expected. Thanks for this very useful tip.

I still dont understand why ghci is not using the default thread to
run the binding, but from now on I will be more alert when binding to
libraries that uses threads.

Theres something else I also dont understood about FFI: When trying to
debug the problem I've written many printf statements  but none of
them showed on the screen, but now that the example is working I've
notice that all printed text appears once I exit ghci. Why is that
happening?


More information about the Haskell-Cafe mailing list