Using std :: thread in Node.js Addon

Imagine using the synchronous function from my Node.js addon:

var check_ok = addon.my_function(parameters);
var final_results = addon.final_function(parameters);

But in the method code, I have:

std::thread t[10]; //Global
//...
void my_function(const FunctionCallbackInfo<v8::Value>& args) {
//....
t[0] = thread(random_void_function, [parameters])
t[1] = thread(random_void_function_2, [parameters])
//...
}
//...
void final_results(const FunctionCallbackInfo<v8::Value>& args) {
//...
t[0].join();
t[1].join();
//...Give results.. etc
}

So, I have 2 synchronous addon calls, but this addon uses two threads. One of the functions will start the threads, and the other will join them. Questions: random_void_functionand random_void_function_2will work in parallel? Since my_functionthey final_functionare both synchronous random_void_functionand random_void_function_2block the event loop? From what I see, they are not blocked.

+4
source share
1 answer

Questions: will random_void_function and random_void_function_2 work in parallel?

, . , , ( ).

my_function final_function , random_void_function random_void_function_2 ? , , .

, . addon.my_function . addon.final_results (, addon.final_function) , random_void_function . , addon.final_results .

, , random_void_function .

+1

Source: https://habr.com/ru/post/1623327/


All Articles