Stream: general

Topic: SDK for atomic operations


view this post on Zulip Marcin Kolny (Jul 18 2022 at 16:56):

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

Threads and Atomics in WebAssembly. Contribute to WebAssembly/threads development by creating an account on GitHub.

view this post on Zulip Dan Gohman (Jul 18 2022 at 17:01):

If you pass -matomics to the cc in wasi-sdk, I believe it should emit atomic instructions.

view this post on Zulip Marcin Kolny (Jul 19 2022 at 14:50):

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)

view this post on Zulip bjorn3 (Jul 19 2022 at 14:52):

I tried with _Atomic but that didn't seem to work.

Also if you use -matomics?

view this post on Zulip Marcin Kolny (Jul 19 2022 at 17:31):

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?

view this post on Zulip Dan Gohman (Jul 19 2022 at 17:33):

Ah, the issue there is probably that wasi-sdk's libc++ build is configured without threads support.

view this post on Zulip Marcin Kolny (Jul 19 2022 at 18:23):

@Dan Gohman do you know of any other SDK where this is enabled? Tried with emcc but that doesn't work either

view this post on Zulip Dan Gohman (Jul 19 2022 at 19:10):

Could you say more about what you're looking to do here?

view this post on Zulip Marcin Kolny (Jul 19 2022 at 19:30):

@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

Threads and Atomics in WebAssembly. Contribute to WebAssembly/threads development by creating an account on GitHub.

view this post on Zulip Dan Gohman (Jul 19 2022 at 19:31):

In what context will this mutex be used?

view this post on Zulip Marcin Kolny (Jul 19 2022 at 19:36):

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

Contribute to WebAssembly/wasi-native-threads development by creating an account on GitHub.

view this post on Zulip Dan Gohman (Jul 19 2022 at 19:39):

Perhaps @Andrew Brown may be able to help here.

view this post on Zulip Andrew Brown (Jul 19 2022 at 22:39):

@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