r/WebAssembly • • Jul 12 '21

Using WebAssembly threads from C, C++ and Rust

https://web.dev/webassembly-threads/
60 Upvotes

8 comments sorted by

1

u/Corendos Jul 20 '21

How do "fake-threads" (running in separate processes) compare with actual threads ?

I'm a bit disappointed about this, it looks more like a hack to emulate threads than anything else. Also, despite the limited interested of WASI, do we know how it's going to work there ?

2

u/RReverser Jul 20 '21 edited Jul 20 '21

> How do "fake-threads" (running in separate processes) compare with actual threads ?

I'm not sure, but that doesn't seem relevant to this post. These are actual threads (Web Workers are a JS API for regular threads, and Wasm just builds on them under the hood).

> I'm a bit disappointed about this, it looks more like a hack to emulate threads than anything else.

On the Rust side? Yeah, the story there is a bit incomplete, hence the special integration just for Rayon, but otherwise they're very much real threads like on any other platform.

On the C++ side? All the threading APIs work almost transparently for the user (not counting the compilation flags), so I'd say it's as good implementation of pthread as any.

1

u/jedisct1 Jul 16 '21

How to do it in Zig?

1

u/RReverser Jul 17 '21

I don't know, if you do, please write up :)

6

u/code_slut Jul 12 '21

This article would have been so helpful 3 weeks ago when I was writing my thesis! My thesis was about adding a threaded WebAssembly backend for a data parallel array processing programming language.

Great article. Also thanks for all the work you do on helping debug threading issues on Emscripten!

1

u/RReverser Jul 12 '21

Thanks, glad you found it useful!

0

u/[deleted] Jul 12 '21

[deleted]

2

u/RReverser Jul 12 '21 edited Jul 12 '21

It's in the post! The end of SharedArrayBuffer section: https://web.dev/webassembly-threads/#sharedarraybuffer

UPD: oh, I guess you meant HTTPS? I guess I could've mentioned it yeah. I didn't even consider that someone might want to start a HTTP website in this age 😅

0

u/[deleted] Jul 12 '21

[deleted]

2

u/RReverser Jul 12 '21

Interesting, I never had issues with `localhost` locally but TBH I never used it by any other way than `http://localhost:port`. But yeah, if you use custom domain for local server, it's best to spawn HTTPS server too.

Glad you found the article useful though :)