Fix multi-threading issues (#2013)

- Implement atomic.fence to ensure a proper memory synchronization order
- Destroy exec_env_singleton first in wasm/aot deinstantiation
- Change terminate other threads to wait for other threads in
  wasm_exec_env_destroy
- Fix detach thread in thread_manager_start_routine
- Fix duplicated lock cluster->lock in wasm_cluster_cancel_thread
- Add lib-pthread and lib-wasi-threads compilation to Windows CI
This commit is contained in:
Wenyong Huang
2023-03-08 10:57:22 +08:00
committed by GitHub
parent 7a3d2bfab6
commit f279ba84ee
16 changed files with 167 additions and 42 deletions

View File

@ -116,6 +116,20 @@ os_thread_signal_inited();
#endif /* end of BUILD_TARGET_X86_64/AMD_64 */
#endif /* end of WASM_DISABLE_HW_BOUND_CHECK */
typedef enum os_memory_order {
os_memory_order_relaxed,
os_memory_order_consume,
os_memory_order_acquire,
os_memory_order_release,
os_memory_order_acq_rel,
os_memory_order_seq_cst,
} os_memory_order;
void
bh_atomic_thread_fence(int mem_order);
#define os_atomic_thread_fence bh_atomic_thread_fence
#ifdef __cplusplus
}
#endif

View File

@ -10,7 +10,8 @@ add_definitions(-DHAVE_STRUCT_TIMESPEC)
include_directories(${PLATFORM_SHARED_DIR})
include_directories(${PLATFORM_SHARED_DIR}/../include)
file (GLOB_RECURSE source_all ${PLATFORM_SHARED_DIR}/*.c)
file (GLOB_RECURSE source_all ${PLATFORM_SHARED_DIR}/*.c
${PLATFORM_SHARED_DIR}/*.cpp)
set (PLATFORM_SHARED_SOURCE ${source_all})

View File

@ -0,0 +1,22 @@
/*
* Copyright (C) 2023 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "platform_api_vmcore.h"
#include "platform_api_extension.h"
#if WASM_ENABLE_SHARED_MEMORY != 0
#include <atomic>
void
bh_atomic_thread_fence(int mem_order)
{
std::memory_order order =
(std::memory_order)(std::memory_order::memory_order_relaxed + mem_order
- os_memory_order_relaxed);
std::atomic_thread_fence(order);
}
#endif