Hi all,
I've been trying to implement a binding for the pthread_* functions to
V8, and have been running into a segfaults -- probably because of my
lack of understanding of V8 scope and context.
Here is how I create the thread (posix_PTHREAD is an object with an
internal field to store the thread value)
static Handle<v8::Value> js_pthread_create (Arguments& args) {
HandleScope handlescope;
Handle<Function> callback = Handle<Function>::Cast(args[(0)])
pthread_t* thread = (pthread_t*) malloc(sizeof(pthread_t));
Persistent<Object> result = Persistent<Object>::New(posix_PTHREAD
(thread));
result->Set(JS_str("callback"),callback);
posix_pthread_create_callback((void*)*result);
pthread_create(thread, NULL, posix_pthread_create_callback,
(void*)*result);
return result
}
void* posix_pthread_create_callback(void* context) {
Locker locker;
HandleScope HandleScope;
printf("Starting new thread...\n");
Object* context_obj = reinterpret_cast<Object*>
(context);
Handle<Function> callback_v = Handle<Function>::Cast(context_obj->Get
(JS_str("callback")));
callback_v->Call(Context::GetCurrent()->Global(), 0, NULL);
}
So basically, I pass posix_pthread_create_callback a persistent object
(that I will garbage-collect at thread termination) containing a
reference to a callback. However, the "Call"ing of the functions
crashes... and I can't tell where the problem is.
I suppose it is related to "Context::GetCurrent()->Global()"... what
would be the proper way to do this ?
-- Sébastien
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---