Add lock to protect the operations of accessing exec env (#1991)

Data race may occur when accessing exec_env's fields, e.g. suspend_flags
and handle. Add lock `exec_env->wait_lock` for them to resolve the issue.
This commit is contained in:
Enrico Loparco
2023-02-27 12:53:41 +01:00
committed by GitHub
parent 38c67b3f48
commit 52e26e59cf
5 changed files with 31 additions and 4 deletions

View File

@ -208,10 +208,17 @@ void
wasm_exec_env_set_thread_info(WASMExecEnv *exec_env)
{
uint8 *stack_boundary = os_thread_get_stack_boundary();
#if WASM_ENABLE_THREAD_MGR != 0
os_mutex_lock(&exec_env->wait_lock);
#endif
exec_env->handle = os_self_thread();
exec_env->native_stack_boundary =
stack_boundary ? stack_boundary + WASM_STACK_GUARD_SIZE : NULL;
exec_env->native_stack_top_min = (void *)UINTPTR_MAX;
#if WASM_ENABLE_THREAD_MGR != 0
os_mutex_unlock(&exec_env->wait_lock);
#endif
}
#if WASM_ENABLE_THREAD_MGR != 0