理解v8的Isolate调度

这两天看了一下v8的在多线程情况下多个Isolate的调度原理,别的不多说了还是先看一下测试代码吧

#include 
#include 
#include 
#include 

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 new context.
	Handle context = Context::New(isolate);

	// Here's how you could create a Persistent handle to the context, if needed.
	Persistent persistent_context(isolate, context);

	// Enter the created context for compiling and
	// running the hello world script.
	Context::Scope context_scope(context);

	// Create a string containing the JavaScript source code.
	Handle source = String::New(args->message);

	// Compile the source code.
	Handle
                    
                    

你可能感兴趣的:(c/c++相关)