-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
thread spawn is broken on wasm32-wasip1-threads for building library #146843
Copy link
Copy link
Open
Labels
A-threadArea: `std::thread`Area: `std::thread`C-bugCategory: This is a bug.Category: This is a bug.O-wasiOperating system: Wasi, Webassembly System InterfaceOperating system: Wasi, Webassembly System InterfaceO-wasip1-threadsOperating system: *-wasmp1-threads, WASI Preview1 with atomics and threadsOperating system: *-wasmp1-threads, WASI Preview1 with atomics and threadsO-wasmTarget: WASM (WebAssembly), http://webassembly.org/Target: WASM (WebAssembly), http://webassembly.org/T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-threadArea: `std::thread`Area: `std::thread`C-bugCategory: This is a bug.Category: This is a bug.O-wasiOperating system: Wasi, Webassembly System InterfaceOperating system: Wasi, Webassembly System InterfaceO-wasip1-threadsOperating system: *-wasmp1-threads, WASI Preview1 with atomics and threadsOperating system: *-wasmp1-threads, WASI Preview1 with atomics and threadsO-wasmTarget: WASM (WebAssembly), http://webassembly.org/Target: WASM (WebAssembly), http://webassembly.org/T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I tried this code:
I expected to see this happen: success
Instead, this happened: infinity loop
Meta
rustc --version --verbose:This relates to rust-lang/rust#108097
When generating as a bin, if you attempt to perform a thread spawn before the generated _start function is called, the program falls into an infinite loop and halts. This issue occurs regardless of whether you use nightly or not.
Furthermore, when building as a lib, thread spawning does not work at all.
The reason is that in the case of bin,
crt1-command.ois linked, and within the generated_startfunction,__wasi_init_tpis invoked, which initializes the thread-related state. However, in the case of lib, the expectedcrt1-reactor.oshould be linked, but its_initializefunction is not exported, so initialization never happens and threads fail to work correctly.As a workaround, you can use the following:
As also noted in
#146721,
I honestly cannot understand why thread::spawn is so broken in this area.