I tried this code:
https://github.com/Brooooooklyn/rust-wasi-thread-local-stuck
use std::cell::RefCell;
use std::collections::HashMap;
thread_local! {
static THREAD_LOCAL_DATA: RefCell<HashMap<u32, u32>> = RefCell::new(HashMap::new());
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn set_thread_local_data(key: u32, value: u32) {
THREAD_LOCAL_DATA.with(|data| {
data.borrow_mut().insert(key, value);
});
}
I expected to see this happen: Program run and exit normally
Instead, this happened: hang forever
(edit): See toyobayashi/emnapi#136 (comment) for where and why
Meta
rustc --version --verbose:
rustc 1.85.0 (4d91de4e4 2025-02-17)
binary: rustc
commit-hash: 4d91de4e48198da2e33413efdcd9cd2cc0c46688
commit-date: 2025-02-17
host: aarch64-apple-darwin
release: 1.85.0
LLVM version: 19.1.7
Background
The NAPI-RS project enables the compilation of Rust projects to the wasm32-wasip1-threads target, allowing them to run in Node.js. However, since Node.js doesn’t natively support WASI threads, we simulate a threaded environment using emnapi. This setup worked effectively until version 1.85.0. Many projects, such as rolldown and rspack, have been successfully compiled to WebAssembly targets to run seamlessly on platforms like StackBlitz and in web browsers.
I tried this code:
https://github.com/Brooooooklyn/rust-wasi-thread-local-stuck
I expected to see this happen: Program run and exit normally
Instead, this happened: hang forever
(edit): See toyobayashi/emnapi#136 (comment) for where and why
Meta
rustc --version --verbose:Background
The NAPI-RS project enables the compilation of Rust projects to the
wasm32-wasip1-threadstarget, allowing them to run in Node.js. However, since Node.js doesn’t natively support WASI threads, we simulate a threaded environment using emnapi. This setup worked effectively until version1.85.0. Many projects, such as rolldown and rspack, have been successfully compiled to WebAssembly targets to run seamlessly on platforms like StackBlitz and in web browsers.