Hi Benjamin,
I think you want to do is to send an asynchronous message from that thread into
the main loop thread, and then you can send it from there to the javascript
layer. You can use libuv's uv_async_init and uv_async_send, which is described
here:
http://nikhilm.github.com/uvbook/threads.html#inter-thread-communication
Hope this helps,
--
Pedro
On Saturday, January 12, 2013 at 10:23 PM, Benjamin Farrell wrote:
> Hey everyone, I'm having so much fun making my first AddOn for Node. I ran
> into one stumbling block, and a lot of things I see in researching the web
> aren't complete enough for me to understand, or outdated information.
>
> Anyway - I spawn a thread that performs a bunch of work. During the
> processing of that work, I'd like to call out an event to Node.js. I can
> almost do that, but I get a segmentation fault. Now, I know I've been warned
> that calling a Node function from a separate thread would result in a seg
> fault - but I thought I'd try something lame and call a a function, and THAT
> function would be scoped to node, thinking it might be OK.
>
> When that didn't work, I actually stopped the thread from running, and had my
> callback on the thread complete callback. Still a seg fault when put there!
>
> So what's the strategy here?
>
> If it helps, here's my code:
>
> void onFrameWorkerThreadComplete (uv_work_t *req) {
> HandleScope scope;
>
> Baton *m = (Baton *)req->data;
> m->callback.Dispose();
> delete m;
> delete req;
>
> const unsigned argc = 1;
> Local<Value> argv[argc] = { Local<Value>::New(String::New("hello world")) };
> JSCallback->Call(Context::GetCurrent()->Global(), argc, argv);
> }
>
>
> The callback does work in a different context - like I could put the callback
> in another method and it would fire, calling the Javascript method and
> outputting the string. Its just that when I put it anywhere near these
> threads, it seg faults.
>
> I'm sure I'm just doing things completely wrong, and there's a trick I'm not
> aware of.
>
> thanks!
>
> --
> 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]
> (mailto:[email protected])
> To unsubscribe from this group, send email to
> [email protected]
> (mailto:[email protected])
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
--
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