wasm-micro-runtime icon indicating copy to clipboard operation
wasm-micro-runtime copied to clipboard

Global mutex does not work

Open xianjimli opened this issue 1 year ago • 1 comments

Global mutex does not work

The mutex is created at here:

* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 16.1
  * frame #0: 0x0000000102d984a8 libvmlib.dylib`create_cluster_info(cluster=0x0000000100505b50) at lib_pthread_wrapper.c:396:46
    frame #1: 0x0000000102d98254 libvmlib.dylib`append_thread_info_node(thread_info=0x0000000100505c18) at lib_pthread_wrapper.c:453:22
    frame #2: 0x0000000102d97514 libvmlib.dylib`pthread_mutex_init_wrapper(exec_env=0x00000001004c4d00, mutex=0x0000000300044f38, attr=0x0000000300000000) at lib_pthread_wrapper.c:837:10
    frame #3: 0x0000000102e12418 libvmlib.dylib`call_func at invokeNative_aarch64.s:71
    frame #4: 0x0000000102db8260 libvmlib.dylib`wasm_interp_call_func_native(module_inst=<unavailable>, exec_env=<unavailable>, cur_func=<unavailable>, prev_frame=<unavailable>) at wasm_interp_classic.c:1229:15
    frame #5: 0x0000000102dd1e2c libvmlib.dylib`wasm_interp_call_func_bytecode(module=0x00000001004bdd70, exec_env=0x00000001004c4d00, cur_func=0x00000001004bf178, prev_frame=0x00000001004c5be0) at wasm_interp_classic.c:6455:17
    frame #6: 0x0000000102db7bc4 libvmlib.dylib`wasm_interp_call_wasm(module_inst=0x00000001004bdd70, exec_env=0x00000001004c4d00, function=0x00000001004bf298, argc=0, argv=0x0000000000000000) at wasm_interp_classic.c:7254:13
    frame #7: 0x0000000102de7ba0 libvmlib.dylib`call_wasm_with_hw_bound_check(module_inst=0x00000001004bdd70, exec_env=0x00000001004c4d00, function=0x00000001004bf298, argc=0, argv=0x0000000000000000) at wasm_runtime.c:3336:9
    frame #8: 0x0000000102de7a20 libvmlib.dylib`wasm_call_function(exec_env=0x00000001004c4d00, function=0x00000001004bf298, argc=0, argv=0x0000000000000000) at wasm_runtime.c:3408:5
    frame #9: 0x0000000102de73bc libvmlib.dylib`execute_post_instantiate_functions(module_inst=0x00000001004bdd70, is_sub_inst=false, exec_env_main=0x0000000000000000) at wasm_runtime.c:1495:13
    frame #10: 0x0000000102de5aac libvmlib.dylib`wasm_instantiate(module=0x00000001004aa720, parent=0x0000000000000000, exec_env_main=0x0000000000000000, stack_size=262144, heap_size=31981568, max_memory_pages=0, error_buf="", error_buf_size=128) at wasm_runtime.c:3060:10
    frame #11: 0x0000000102dafe7c libvmlib.dylib`wasm_runtime_instantiate_internal(module=0x00000001004aa720, parent=0x0000000000000000, exec_env_main=0x0000000000000000, stack_size=262144, heap_size=31981568, max_memory_pages=0, error_buf="", error_buf_size=128) at wasm_runtime_common.c:1575:44
    frame #12: 0x0000000102daff38 libvmlib.dylib`wasm_runtime_instantiate(module=0x00000001004aa720, stack_size=262144, heap_size=31981568, error_buf="", error_buf_size=128) at wasm_runtime_common.c:1595:12

but it is destroyed at here:

* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 17.1
  * frame #0: 0x0000000102d96808 libvmlib.dylib`destroy_cluster_info(cluster=0x0000000100505b50) at lib_pthread_wrapper.c:415:44
    frame #1: 0x0000000102d96758 libvmlib.dylib`lib_pthread_destroy_callback(cluster=0x0000000100505b50) at lib_pthread_wrapper.c:426:5
    frame #2: 0x0000000102deadb8 libvmlib.dylib`destroy_cluster_visitor(node=0x00000001004a9328, user_data=0x0000000100505b50) at thread_manager.c:331:5
    frame #3: 0x0000000102dead6c libvmlib.dylib`traverse_list(l=0x0000000102e22190, visitor=(libvmlib.dylib`destroy_cluster_visitor at thread_manager.c:327), user_data=0x0000000100505b50) at thread_manager.c:82:9
    frame #4: 0x0000000102dea618 libvmlib.dylib`wasm_cluster_destroy(cluster=0x0000000100505b50) at thread_manager.c:337:5
    frame #5: 0x0000000102deafc4 libvmlib.dylib`wasm_cluster_del_exec_env_internal(cluster=0x0000000100505b50, exec_env=0x00000001004c4d00, can_destroy_cluster=true) at thread_manager.c:432:13
    frame #6: 0x0000000102deae50 libvmlib.dylib`wasm_cluster_del_exec_env(cluster=0x0000000100505b50, exec_env=0x00000001004c4d00) at thread_manager.c:446:12
    frame #7: 0x0000000102da9080 libvmlib.dylib`wasm_exec_env_destroy(exec_env=0x00000001004c4d00) at wasm_exec_env.c:211:9
    frame #8: 0x0000000102de7430 libvmlib.dylib`execute_post_instantiate_functions(module_inst=0x00000001004bdd70, is_sub_inst=false, exec_env_main=0x0000000000000000) at wasm_runtime.c:1511:13
    frame #9: 0x0000000102de5aac libvmlib.dylib`wasm_instantiate(module=0x00000001004aa720, parent=0x0000000000000000, exec_env_main=0x0000000000000000, stack_size=262144, heap_size=31981568, max_memory_pages=0, error_buf="", error_buf_size=128) at wasm_runtime.c:3060:10
    frame #10: 0x0000000102dafe7c libvmlib.dylib`wasm_runtime_instantiate_internal(module=0x00000001004aa720, parent=0x0000000000000000, exec_env_main=0x0000000000000000, stack_size=262144, heap_size=31981568, max_memory_pages=0, error_buf="", error_buf_size=128) at wasm_runtime_common.c:1575:44
    frame #11: 0x0000000102daff38 libvmlib.dylib`wasm_runtime_instantiate(module=0x00000001004aa720, stack_size=262144, heap_size=31981568, error_buf="", error_buf_size=128) at wasm_runtime_common.c:1595:12

xianjimli avatar Aug 13 '24 08:08 xianjimli

@xianjimli Thanks for reporting the issue! I have several questions: which global mutex do you refer to, and do you mean the global mutex is accessed after it is destroyed? BTW, could you upload the wasm file to reproduce the issue?

wenyongh avatar Aug 15 '24 03:08 wenyongh