Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to call a function in main v8 loop from a different thread

How to call a function in main v8 loop from a different thread

Problem

I am trying to implement an audio module for nodejs which involves a Neural Network.

This neural network has 2 types of nodes

  1. Pure C++
  2. C++ based on JAVASCRIPT ( which involves calling a javascript function )

As far as i know its not possible to call any Function which involves v8 from a different thread. And if i return to the main thread i will lose my traverse in the neural network.

How to implement a call to a function in the main thread from a different thread?

Problem courtesy of: Shrek

Solution

I figured it out with the help of

@indutny in the #libuv channel.

What I do now is dispatch the call to main thread via

uv_async_send

function defined in libuv.h, since the function is non-blocking. I also use a semaphore to wait till the execution of the javascript function is complete in order to avoid the corrupted parse.

Solution courtesy of: Shrek

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

How to call a function in main v8 loop from a different thread

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×