Fix execute_main not wait for other threads (#1137)
Fix wasm_application_execute_main/wasm_application_execute_func not waiting for other threads to terminate in multi-thread mode, which causes that the exception thrown by other threads may haven't been spreaded to current main thread, and cannot be detected by the caller, as reported in #1131.
This commit is contained in:
@ -10,6 +10,9 @@
|
||||
#if WASM_ENABLE_AOT != 0
|
||||
#include "../aot/aot_runtime.h"
|
||||
#endif
|
||||
#if WASM_ENABLE_THREAD_MGR != 0
|
||||
#include "../libraries/thread-mgr/thread_manager.h"
|
||||
#endif
|
||||
|
||||
static void
|
||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||
@ -76,9 +79,8 @@ check_main_func_type(const WASMType *type)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc,
|
||||
char *argv[])
|
||||
static bool
|
||||
execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, char *argv[])
|
||||
{
|
||||
WASMFunctionInstanceCommon *func;
|
||||
WASMType *func_type = NULL;
|
||||
@ -203,6 +205,28 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc,
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc,
|
||||
char *argv[])
|
||||
{
|
||||
bool ret;
|
||||
#if WASM_ENABLE_THREAD_MGR != 0
|
||||
WASMCluster *cluster;
|
||||
WASMExecEnv *exec_env;
|
||||
#endif
|
||||
|
||||
ret = execute_main(module_inst, argc, argv);
|
||||
|
||||
#if WASM_ENABLE_THREAD_MGR != 0
|
||||
exec_env = wasm_runtime_get_exec_env_singleton(module_inst);
|
||||
if (exec_env && (cluster = wasm_exec_env_get_cluster(exec_env))) {
|
||||
wasm_cluster_wait_for_all_except_self(cluster, exec_env);
|
||||
}
|
||||
#endif
|
||||
|
||||
return (ret && !wasm_runtime_get_exception(module_inst)) ? true : false;
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||
static WASMModuleInstance *
|
||||
get_sub_module_inst(const WASMModuleInstance *parent_module_inst,
|
||||
@ -351,9 +375,9 @@ union ieee754_double {
|
||||
} ieee;
|
||||
};
|
||||
|
||||
bool
|
||||
wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
|
||||
const char *name, int32 argc, char *argv[])
|
||||
static bool
|
||||
execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
|
||||
int32 argc, char *argv[])
|
||||
{
|
||||
WASMFunctionInstanceCommon *target_func;
|
||||
WASMModuleInstanceCommon *target_inst;
|
||||
@ -689,3 +713,25 @@ fail:
|
||||
os_printf("%s\n", exception);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
|
||||
const char *name, int32 argc, char *argv[])
|
||||
{
|
||||
bool ret;
|
||||
#if WASM_ENABLE_THREAD_MGR != 0
|
||||
WASMCluster *cluster;
|
||||
WASMExecEnv *exec_env;
|
||||
#endif
|
||||
|
||||
ret = execute_func(module_inst, name, argc, argv);
|
||||
|
||||
#if WASM_ENABLE_THREAD_MGR != 0
|
||||
exec_env = wasm_runtime_get_exec_env_singleton(module_inst);
|
||||
if (exec_env && (cluster = wasm_exec_env_get_cluster(exec_env))) {
|
||||
wasm_cluster_wait_for_all_except_self(cluster, exec_env);
|
||||
}
|
||||
#endif
|
||||
|
||||
return (ret && !wasm_runtime_get_exception(module_inst)) ? true : false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user