// This one eats 100 Mb per second

#include "v8.h"
#include "windows.h"
#include "stdio.h"
#include "process.h"
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "winmm.lib")
using namespace v8;

Handle<Value> cppfoo(const Arguments& args)
{
        Handle<Context> context = Context::GetCurrent();
        {
                v8::Unlocker unlocker;
                Sleep(0);
        }
        return Integer::New(1);
 }



void thread (void* p)
{

        Persistent<Context> context;
        Persistent<Function> foo;

        {
                v8::Locker locker;
                HandleScope handle_scope;

                Handle<ObjectTemplate> global = ObjectTemplate::New();
                global->Set(String::NewSymbol("cppfoo"), FunctionTemplate::New
(cppfoo));
                context = Context::New(NULL, global);

                Context::Scope context_scope(context);
                TryCatch try_catch;
                Script::Compile(String::New("function foo(){  cppfoo(); 
}"))->Run();

                foo = Persistent<Function>::New(Handle<Function>::Cast(context-
>Global()->Get(String::New("foo"))));
        }

        while (true)
        {

                int n_calls = 1000;
                while (n_calls--)
                {

                        {
                                v8::Locker locker;
                                HandleScope handle_scope;
                                Context::Scope context_scope(context);
                                TryCatch try_catch;

                                const int argc = 1;
                                Local<Value> argv[argc] = { 
String::New("some_string") };
                                Local<Value> result = 
foo->Call(context->Global(), argc, argv);

                        }

                        Sleep(0);

                }

                Sleep(1);

        }

        v8::Locker locker;
        foo.Dispose();
        context.Dispose();

}



int main(int argc, char *argv[])
{
        _beginthread(thread, 0, 0);
        _beginthread(thread, 0, 0);
        while (true) Sleep(1000);
        return 0;
}

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

Reply via email to