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:
@ -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:
|
||||
|
||||
Reference in New Issue
Block a user