pmed / v8pp

Bind C++ functions and classes into V8 JavaScript engine
http://pmed.github.io/v8pp/
Other
887 stars 119 forks source link

Support context scopes and explicit enters #133

Closed cr-mitmit closed 3 years ago

cr-mitmit commented 4 years ago

Using v8 in a multi-threaded environment requires explicit calls to enter and exit the context. This patch adds support for asking context to switch to explicit enter/exit pairs (default is still to implicitly Enter the context)

In addition, this patch introduces the context::context_scope class which is an RAII to Enter and Exit the context. When the isolate is owned by the context, in addition to enter the context, it also acquires a v8::Locker and enters the Isolate.

This means that by acquiring a context_scope you can safely call JS from any thread.

pmed commented 3 years ago

@cr-mitmit, thanks! it's been merged onto the master, and c++17 branches.