想象一下,我使用 Node.js 插件中的同步函数:
var check_ok = addon.my_function(parameters);
var final_results = addon.final_function(parameters);
Run Code Online (Sandbox Code Playgroud)
但在方法代码中我有:
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
}
Run Code Online (Sandbox Code Playgroud)
所以我有两个插件的同步调用,但在这个插件中使用了两个线程。一个函数将启动线程,另一个函数将加入它们。问题是:random_void_function并且random_void_function_2会并行运行吗?既然my_function和final_function是同步的,那么random_void_function和random_void_function_2会阻塞事件循环吗?据我所知,他们没有阻止。
想象一下,我使用C++11 threads.该线程将运行一个函数malloc.之后我将使用join没有free(记忆).所以,我杀了线程.预计内存会自动释放吗?