So I'm making an addon for node.js as in: http://nodejs.org/api/addons.html#addons_wrapping_c_objects.
However: my class has a pthread that loops forever and performs callbacks via uv_async_send() as suggested in http://nikhilm.github.io/uvbook/threads.html.
This callback function needs to access non-static class variables, I do that by setting: async.data = (void*) this; and in the callback function: MyClass* obj = (MyClass*)(handle->data);, so that i can access the data via: obj->myvar.
What happens though, is that the callback function is called after the object has been destructed already. I'm wondering how to prevent this from happening, preferably without the need for extra javascript code.
In case you wonder why the callback needs to access member variables: it's a buffer that is filled by the seperate thread, which passed as argument to the javascript callback.
Thanks in advance.