Use shared memory lock for threads generated from same module (#1960)
Multiple threads generated from the same module should use the same lock to protect the atomic operations. Before this PR, each thread used a different lock to protect atomic operations (e.g. atomic add), making the lock ineffective. Fix #1958.
This commit is contained in:
@ -1587,15 +1587,6 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst, uint32 stack_size,
|
||||
module_inst->e =
|
||||
(WASMModuleInstanceExtra *)((uint8 *)module_inst + extra_info_offset);
|
||||
|
||||
#if WASM_ENABLE_SHARED_MEMORY != 0
|
||||
if (os_mutex_init(&module_inst->e->mem_lock) != 0) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"create shared memory lock failed");
|
||||
goto fail;
|
||||
}
|
||||
module_inst->e->mem_lock_inited = true;
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||
module_inst->e->sub_module_inst_list =
|
||||
&module_inst->e->sub_module_inst_list_head;
|
||||
@ -2159,11 +2150,6 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_SHARED_MEMORY != 0
|
||||
if (module_inst->e->mem_lock_inited)
|
||||
os_mutex_destroy(&module_inst->e->mem_lock);
|
||||
#endif
|
||||
|
||||
if (module_inst->e->c_api_func_imports)
|
||||
wasm_runtime_free(module_inst->e->c_api_func_imports);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user