这两天看了一下v8的在多线程情况下多个Isolate的调度原理,别的不多说了还是先看一下测试代码吧
#include <v8.h>
#include <iostream>
#include <pthread.h>
#include <unistd.h>
using namespace v8;
typedef struct _Args
{
Isolate* isolate;
char message[256];
} Args;
void* test(void* data)
{
Args* args = (Args*) data;
Isolate* isolate = args->isolate;
if (isolate == NULL)
{
std::cout << "null isolate found" << std::endl;
delete args;
return NULL;
}
Isolate* current = Isolate::GetCurrent();
if (current == NULL)
{
std::cout << "current isolate is null before locker" << std::endl;
}
else
{
std::cerr << "current isolate is not null before locker" << std::endl;
}
Locker locker(isolate);
current = Isolate::GetCurrent();
if (current != NULL)
{
std::cerr << "current isolate is not null after locker" << std::endl;
}
else
{
std::cout << "current isolate is null after locker" << std::endl;
}
Isolate::Scope isolate_scope(isolate);
current = Isolate::GetCurrent();
if (current == NULL)
{
std::cerr << "current isolate is null after enter" << std::endl;
}
else
{
std::cout << "current isolate is not null after enter" << std::endl;
}
// Create a stack-allocated handle scope.
HandleScope handle_scope(isolate);
// Create a n