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

@ -123,19 +123,16 @@ thread_spawn_wrapper(wasm_exec_env_t exec_env, uint32 start_arg)
thread_start_arg->arg = start_arg;
thread_start_arg->start_func = start_func;
os_mutex_lock(&exec_env->wait_lock);
ret = wasm_cluster_create_thread(exec_env, new_module_inst, false,
thread_start, thread_start_arg);
if (ret != 0) {
LOG_ERROR("Failed to spawn a new thread");
goto thread_spawn_fail;
}
os_mutex_unlock(&exec_env->wait_lock);
return thread_id;
thread_spawn_fail:
os_mutex_unlock(&exec_env->wait_lock);
deallocate_thread_id(thread_id);
thread_preparation_fail: