Closed ghost closed 1 year ago
Hi Ron,
Thanks for the proposal. I've never used V8 with multiple threads and isolates, and I hope it would work.
Do you mean a static type_index class_singleton<T>::class_type
member variables? I've got another issue with it. These static variables don't work with multiple DLLs, since they are declared in a header file which has been included into each DLL.
To resolve this I'm going to revert back std::type_index
and language RTTI for class idetification, as it was used some time ago (before 7c1eeb429259e87d72190dcdad22678bb5e03556). This would require an additional effort from a library user to enable RTTI for Node.js addon, because node-gyp
has set -fno-rtti
flag by default :-/ (see nodejs/node-gyp#26)
Another static variable is instances
map in a function class_singleton::class_instances(v8::Isolate* isolate)
when v8::Isolate slot is not used.
This global instances
map can't be thread_local
. As I remember, static variables initialization is thread-safe in C++11, so I only need to protect access to the instances
with std::mutex
.
No further interest.
I wanted to use v8pp::class_ concurrently in separate threads/isolates and realized that it shouldn’t work because class_singleton had some static variables.
I tried replacing all static variables with thread_local ones and then my program seemed to work well, but worried that this change may break existing code. (e.g. Sharing a v8::Isolate among threads with v8::Locker)
Think up two solution:
like this:
Solution 1 is ad-hoc but easy. Solution 2 is more general but affects many api.