Hi all, does anybody know if there's already an SDK for C or C++ that generates atomics proposed in the proposal: https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md? I've tried wasi-sdk but couldn't get it to work. Many thanks in advance
If you pass -matomics
to the cc
in wasi-sdk, I believe it should emit atomic instructions.
Sorry, I should have been more clear; what C/C++ instructions actually emit atomic instructions in webassembly? I tried with _Atomic but that didn't seem to work. If anyone has any code example, that would be really helpful (mainly I'm interested in wait
and notify
)
I tried with _Atomic but that didn't seem to work.
Also if you use -matomics
?
hi @bjorn3 I think it still doesn't work. This is my simple application:
#include <atomic>
int main()
{
std::atomic_flag atomicFlag{};
atomicFlag.wait(false);
return 0;
}
and I compile it with a command: /opt/wasi-sdk16/bin/clang++ -std=c++11 -Wno-format atomic.cpp -matomics
In the output WASM file I can see that the wait was implemented using spins rather than atomic wait operations (memory.atomic.wait32
). I wonder if any SDK currently can translate the C++ code (or any other language) to use atomics?
Ah, the issue there is probably that wasi-sdk's libc++ build is configured without threads support.
@Dan Gohman do you know of any other SDK where this is enabled? Tried with emcc but that doesn't work either
Could you say more about what you're looking to do here?
@Dan Gohman I'm trying to implement a mutex just like in the proposal here: https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md
In what context will this mutex be used?
I'd like to implement wasi native threads (like in the proposal https://github.com/WebAssembly/wasi-native-threads) in WASM user space with only having the thread_spawn syscall. I need conditionals for mutex, but not only for that but also for thread pool
Perhaps @Andrew Brown may be able to help here.
@Marcin Kolny, sounds like we're interested in the same things; ping me if you want to discuss more
Last updated: Dec 23 2024 at 12:05 UTC