thread-mgr: Fix spread "wasi proc exit" exception and atomic.wait issues (#1988)
Raising "wasi proc exit" exception, spreading it to other threads and then clearing it in all threads may result in unexpected behavior: the sub thread may end first, handle the "wasi proc exit" exception and clear exceptions of other threads, including the main thread. And when main thread's exception is cleared, it may continue to run and throw "unreachable" exception. This also leads to some assertion failed. Ignore exception spreading for "wasi proc exit" and don't clear exception of other threads to resolve the issue. And add suspend flag check after atomic wait since the atomic wait may be notified by other thread when exception occurs.
This commit is contained in:
@ -225,7 +225,9 @@ wasm_cluster_create(WASMExecEnv *exec_env)
|
||||
/* Prepare the aux stack top and size for every thread */
|
||||
if (!wasm_exec_env_get_aux_stack(exec_env, &aux_stack_start,
|
||||
&aux_stack_size)) {
|
||||
#if WASM_ENABLE_LIB_WASI_THREADS == 0
|
||||
LOG_VERBOSE("No aux stack info for this module, can't create thread");
|
||||
#endif
|
||||
|
||||
/* If the module don't have aux stack info, don't throw error here,
|
||||
but remain stack_tops and stack_segment_occupied as NULL */
|
||||
@ -1131,9 +1133,14 @@ set_exception_visitor(void *node, void *user_data)
|
||||
WASMModuleInstance *curr_wasm_inst =
|
||||
(WASMModuleInstance *)get_module_inst(curr_exec_env);
|
||||
|
||||
bh_memcpy_s(curr_wasm_inst->cur_exception,
|
||||
sizeof(curr_wasm_inst->cur_exception),
|
||||
wasm_inst->cur_exception, sizeof(wasm_inst->cur_exception));
|
||||
/* Only spread non "wasi proc exit" exception */
|
||||
if (!strstr(wasm_inst->cur_exception, "wasi proc exit")) {
|
||||
bh_memcpy_s(curr_wasm_inst->cur_exception,
|
||||
sizeof(curr_wasm_inst->cur_exception),
|
||||
wasm_inst->cur_exception,
|
||||
sizeof(wasm_inst->cur_exception));
|
||||
}
|
||||
|
||||
/* Terminate the thread so it can exit from dead loops */
|
||||
set_thread_cancel_flags(curr_exec_env);
|
||||
}
|
||||
@ -1203,4 +1210,4 @@ bool
|
||||
wasm_cluster_is_thread_terminated(WASMExecEnv *exec_env)
|
||||
{
|
||||
return (exec_env->suspend_flags.flags & 0x01) ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user