Hello Ben & Fedor,
Thanks. It worked well.
On Sunday, 2 September 2012 16:51:17 UTC+5:30, Ben Noordhuis wrote:
>
>
> It's a thread safety issue but it's got nothing to do with mutexes:
> the JS object gets garbage collected while the work request is
> running. You need something like the patch below to make it safe.
>
> diff --git a/mutex-test.cc b/mutex-test.cc
> index 3953a4d..3605612 100644
> --- a/mutex-test.cc
> +++ b/mutex-test.cc
> @@ -39,6 +39,8 @@ public:
>
> NativeLibrary* GetHandle();
> void ReturnHandle(NativeLibrary* handle);
> + void Ref() { node::ObjectWrap::Ref(); }
> + void Unref() { node::ObjectWrap::Unref(); }
>
> private:
> Foo()
> @@ -142,6 +144,7 @@ void after_work(uv_work_t *req)
> data->callback->Call(Context::GetCurrent()->Global(), 2, argv);
> }
>
> + data->clazz->Unref();
> data->callback.Dispose();
> delete data;
> data = NULL;
> @@ -184,6 +187,7 @@ Handle<Value> Foo::Process(const Arguments& args)
> data->request.data = data;
> data->callback =
> Persistent<Function>::New(Local<Function>::Cast(args[1]));
> data->clazz = ObjectWrap::Unwrap<Foo>(args.This());
> + data->clazz->Ref();
>
> uv_queue_work(uv_default_loop(), &data->request,
> perform_work_async, after_work);
>
This makes perfect sense and it works well. But I am wondering why
everything was working when I add a delay ?
Thanks for the help.
Navaneeth
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en