我正在尝试在多线程中创建新的Isolate
并出现错误。
说明:
# Fatal error in , line 0
# Check failed: embedded_blob() == StickyEmbeddedBlob().
代码:
#include <iostream>
#include <thread>
#include "include/libplatform/libplatform.h"
#include "include/v8.h"
using namespace v8;
using namespace std;
typedef void* v8_Isolate;
unique_ptr<Platform> v8_latform;
void __cdecl V8_Initialize()
{
v8_latform = platform::NewDefaultPlatform();
V8::InitializePlatform(v8_latform.get());
V8::Initialize();
}
void __cdecl V8_Destroy()
{
V8::Dispose();
V8::ShutdownPlatform();
}
v8_Isolate __cdecl V8_New_Isolate()
{
Isolate::CreateParams create_params = Isolate::CreateParams();
create_params.array_buffer_allocator = ArrayBuffer::Allocator::NewDefaultAllocator();
return (v8_Isolate)Isolate::New(create_params);
}
void __cdecl V8_Dispose_Isolate(v8_Isolate isolate)
{
((Isolate*)isolate)->Dispose();
}
class thread_class {
public:
void operator()()
{
auto isolate = V8_New_Isolate();
cout << "isolate created\n";
V8_Dispose_Isolate(isolate);
cout << "isolate destroyed\n";
}
};
void create_threads()
{
for (int i = 0; i < 5; ++i) {
thread_class cls;
thread thd(cls);
thd.detach();
}
}
int main()
{
V8_Initialize();
create_threads();
this_thread::sleep_for(5s);
V8_Destroy();
return 0;
}