Fix multi-threading issues (#2013)
- Implement atomic.fence to ensure a proper memory synchronization order - Destroy exec_env_singleton first in wasm/aot deinstantiation - Change terminate other threads to wait for other threads in wasm_exec_env_destroy - Fix detach thread in thread_manager_start_routine - Fix duplicated lock cluster->lock in wasm_cluster_cancel_thread - Add lib-pthread and lib-wasi-threads compilation to Windows CI
This commit is contained in:
@ -2073,6 +2073,15 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst)
|
||||
if (!module_inst)
|
||||
return;
|
||||
|
||||
if (module_inst->exec_env_singleton) {
|
||||
/* wasm_exec_env_destroy will call
|
||||
wasm_cluster_wait_for_all_except_self to wait for other
|
||||
threads, so as to destroy their exec_envs and module
|
||||
instances first, and avoid accessing the shared resources
|
||||
of current module instance after it is deinstantiated. */
|
||||
wasm_exec_env_destroy(module_inst->exec_env_singleton);
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_DEBUG_INTERP != 0 \
|
||||
|| (WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_JIT != 0 \
|
||||
&& WASM_ENABLE_LAZY_JIT != 0)
|
||||
@ -2155,9 +2164,6 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst)
|
||||
wasm_externref_cleanup((WASMModuleInstanceCommon *)module_inst);
|
||||
#endif
|
||||
|
||||
if (module_inst->exec_env_singleton)
|
||||
wasm_exec_env_destroy(module_inst->exec_env_singleton);
|
||||
|
||||
#if WASM_ENABLE_DUMP_CALL_STACK != 0
|
||||
if (module_inst->frames) {
|
||||
bh_vector_destroy(module_inst->frames);
|
||||
@ -2241,7 +2247,6 @@ call_wasm_with_hw_bound_check(WASMModuleInstance *module_inst,
|
||||
WASMRuntimeFrame *prev_frame = wasm_exec_env_get_cur_frame(exec_env);
|
||||
uint8 *prev_top = exec_env->wasm_stack.s.top;
|
||||
#ifdef BH_PLATFORM_WINDOWS
|
||||
const char *exce;
|
||||
int result;
|
||||
bool has_exception;
|
||||
char exception[EXCEPTION_BUF_LEN];
|
||||
|
||||
Reference in New Issue
Block a user