On Thu, Sep 8, 2016 at 11:25 PM, Daniel Burchardt <[email protected]> wrote: > Hi, > > I try implement setTimeout in v8. I have problem: how i can execute js code > in other thread in this same context? My code: > > v8::Handle<v8::Value> setTimeoutImpl(const > v8::FunctionCallbackInfo<v8::Value>& info) { > v8::Local<v8::Value> callback(info[0]); > > if (callback->IsFunction()) { > v8::Handle<v8::Function> func = > v8::Handle<v8::Function>::Cast(callback); > > v8::Handle<v8::Value> args[0]; > v8::Handle<v8::Value> result; > result = > func->Call(info.GetIsolate()->GetCurrentContext()->Global(), 0, args); > > info.GetReturnValue().Set(result); > } > } > > I try create new thread like that: > pthread_t tid; > pthread_attr_t tattr; > pthread_attr_init(&tattr); > pthread_attr_setdetachstate(&tattr, > PTHREAD_CREATE_DETACHED); > pthread_create(&tid, &tattr, thread_setTimeout, &ji); > pthread_attr_destroy(&tattr); > > but use v8 in thread is terminated with error segmentation fault... Any one > can help me? I found example but use old api.
You need to create a v8::Locker instance first before entering the isolate and context with v8::Isolate::Scope and v8::Context::Scope respectively. The timer thread will block until the main thread gives it a chance to acquire the locker. (If that all sounds like mumbo jumbo, you need to study v8.h a bit more, particular the sections on v8::Locker and v8::Unlocker.) Traditionally though, most embedders solve this by building their application around an event loop instead of using threads. -- -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
