简体   繁体   English

如何从其他线程在主v8循环中调用函数

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

I am trying to implement an audio module for nodejs which involves a neural network. 我正在尝试为涉及神经网络的nodejs实现音频模块。

This neural network has 2 types of nodes 该神经网络具有2种类型的节点

  1. Pure C++ 纯C ++
  2. C++ based on JAVASCRIPT ( which involves calling a javascript function ) 基于JAVASCRIPT的C ++(涉及调用javascript函数)

As far as i know its not possible to call any function which involves v8 from a different thread. 据我所知,不可能从不同线程调用涉及v8的任何函数。 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? 如何在不同线程中实现对主线程中函数的调用?

I figured it out with the help of 我在

@indutny in the #libuv channel. @libut频道中的@indutny。

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. libuv.h定义的函数,因为该函数是非阻塞的。 I also use a semaphore to wait till the execution of the javascript function is complete in order to avoid the corrupted parse. 我还使用信号量来等待javascript函数的执行完成,以避免解析失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM