Given wasmtime recently landed support, I tried to run a pthread hello world program, and encountered two issues:
thread_spawn
to thread-spawn
to match what wasi-libc uses-Wl,--import-memory,--shared-memory
to satisfy the requirement of importing a shared linear memory, but I couldn't find a way to tell the linker to also export the memoryDid anyone else manage to compile and run a wasm32-wasi-threads module?
Yes, I hope to publish a blog post explaining all the details soon but there are a few remaining issues to work through.
One of the reasons that I'm working on https://github.com/WebAssembly/wasi-sdk/pull/293 is that LLVM 16 provides the --export-memory
and --import-memory
flags in a way that allows the "import, then export" paradigm currently necessary in Wasmtime. Once I have that working I plan to publish a pre-release of wasi-sdk that has all the right tools to make things work.
Ah, --export-memory
, that was new in wasm-ld
and i was looking at the old manpage. I just got an example to run, the behavior is a bit odd but that's kinda expected in the early days. Thanks for your work.
Cheng Shao has marked this topic as resolved.
Yeah, the "import, then export" idea is odd (if that's what you're referring to). @YAMAMOTO Takashi opened up https://github.com/WebAssembly/WASI/issues/502 to discuss this topic generally; feel free to comment there if you have a strong opinion one way or another.
No, I mean the runtime result is incorrect. Though I'm not sure if it's a wasi-libc issue or wasmtime issue, so don't know where to report it..
Oh, that's interesting! If you can diagnose which side it is on, please open a bug. The whole idea of this experimental wasi-sdk release is to bring to light these kinds of issues. Can you say more about the project and what you see?
The bug report is at https://gist.github.com/TerrorJack/a3128331031377a38d50912b0eab609c
Thanks, I'll take a look!
Cheng Shao said:
The bug report is at https://gist.github.com/TerrorJack/a3128331031377a38d50912b0eab609c
you should use large enough --max-memory.
eg.
spacetanuki% /opt/wasi-sdk-19.5g0236e959edbc/bin/clang -Wall --target=wasm32-wasi-threads -pthread thread.c -o thread.wasm -Wl,--import-memory,--max-memory=655360
spacetanuki% ~/git/toywasm/b.thread/toywasm --wasi thread.wasm
Thread - 2
Thread - 1
spacetanuki%
Yeah, that's it... wow, that was unintuitive. I just was taking a look at @Cheng Shao's report today and I can confirm that adding --max-memory=655360
to the linker flags makes everything start working again.
I guess non-PoC code would have error-checking like the following:
int ret = pthread_create(&thread1, NULL, &thread, (void *) thr);
if (ret) {
printf("failed to spawn: %s\n", strerror(ret));
}
Which prints the following for me:
failed to spawn: Resource temporarily unavailable
Last updated: Nov 22 2024 at 17:03 UTC