I was finally picking v8 as the scripting engine for my application when I realized that I missed an important spot: concurrency.
I decided to go with v8 instead of lua because of a couple of key factors, but apparently I can't write thread safe code or a multithreaded task in general, with v8.
On the official docs I found no reference to the concurrent features of v8, they describe the GC, that v8 is written in C++, it's supporting a lot of platforms, and so on, but nothing about threading on both the wiki and the official documentation for embedding v8 inside a C++ application.
Question: how I should be thinking about v8 ? I have to expose my application as a set of single-threaded/thread-safe functions right from C++ ?
V8 is not thread safe, but that doesn't mean you can't use it in a threaded environment. The only stipulation for doing so is using V8's Locker
object, whenever you access any V8 related stuff.
Doing so is really simple, just create a new instance of v8::Locker
and then when you're done with whatever action you were doing in V8, create an instance of v8::Unlocker
In my experience with V8's documentation...it royally sucks and it seems (in my use anyway) the best way to learn how to use it was trial and error.
EDIT: This answer here explains multithreaded use of V8 better than I did:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With