Hi all

I am new to v8.
and I'm trying to make some test codes.

Below is my test code.
It crashes sometimes when executing Context::New function.
Could someone please let me know what the problem is?

#include "stdafx.h"
#include "v8.h"
#include <process.h>
#include <windows.h>

using namespace v8;

static Handle<Value> Print(const Arguments& args)
{
if (!args.Length())
return Undefined();
HandleScope scope;
Handle<Value> arg = args[0];
String::AsciiValue ascii(arg);
printf("%s\n", *ascii);
return Undefined();
}

void __cdecl th(void *arg)
{
Isolate *isolate = Isolate::New();
{
Isolate::Scope isolate_scope(isolate);

HandleScope handle_scope;
char code[1024];
sprintf(code, "print('thread %d(1)');print('thread %d(2)');", (int)arg, 
(int)arg);
 Handle<ObjectTemplate> global = ObjectTemplate::New();
global->Set(String::New("print"), FunctionTemplate::New(Print));
Persistent<Context> context = Context::New(NULL, global);
{
Context::Scope context_scope(context);

Handle<String> source = String::New(code);
Handle<Script> script = Script::Compile(source);

while(1)
Handle<Value> result = script->Run();
}

context.Dispose();
}
isolate->Dispose();
}

int _tmain(int argc, _TCHAR* argv[])
{
_beginthread(th, 0, (void *)1);
_beginthread(th, 0, (void *)2);
_beginthread(th, 0, (void *)3);
_beginthread(th, 0, (void *)4);
while (1)
Sleep(10000);
return 0;
}

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to