Live data from Hacker News

Multithreading Rust and Wasm

rustwasm.github.io

41–47 of 47 posts

Re: Multithreading Rust and Wasm

#41
post #23

The ultimate test would be to see if it is possible to implement an efficient concurrent GC in Rust+WASM. This might require memory fence instructions in WASM.

If it sits on WebWorkers like proposed then no, that won't be possible. WebWorkers are really more multi-process with a somewhat bad IPC mechanism than multi-threading.

Re: Multithreading Rust and Wasm

#42
If the very first thread that's created has to do some bookkeeping that the other created threads rely on, what happens if you create a second thread at the same time as the first one? Or in other words, what happens if you don't instantiate the module on the browser's main thread at all, but instead just spin up 2 web workers that each instantiate the module? Whichever starts first will be thread 0, but what's to stop the other worker from entering its `start` function while the first worker is still busy initializing memory?

Re: Multithreading Rust and Wasm

#43
post #28

Earlier quoted context omitted.

I thought you didn't have raw stack access in wasm, making efficient concurrent GCs impossible practically in native wasm. Hence the GC work to give a higher level API that can more easily be sandboxed.

Virtualization technology is quite mature now, and allows running low-level code (that can access the stack) with safety. Servers run this type of code all the time! Why would we throw away these achievements, and turn WASM (with its potentially simple instruction set) into a complicated monster, that's prone to security problems through its complexity alone? Also, language designers do not want a GC embedded in thei…

> Virtualization technology is quite mature now, and allows running low-level code (that can access the stack) with safety. Servers run this type of code all the time!

Except that "low-level code" is not portable. Which is why we have wasm instead of NaCl.

Incidentally, stack isn't the interesting part. For a good GC on register-rich architectures like AArch64 you really want register roots, which is hard to abstract over portably.

> Also, language designers do not want a GC embedded in their assembly language; they want to implement it themselves, using their own constraints.

I was a language designer in a former life, and I very much want a GC in Web Assembly. Web Assembly doesn't exist in a vacuum: it needs to interact with the DOM for I/O, in much the same way as a Windows program needs to interact with COM to do lots of things. Having two tracing garbage collectors that trace different objects is a nightmare, so I want the same GC that the DOM uses. That is exactly what the wasm GC proposal is.

Re: Multithreading Rust and Wasm

#44

Earlier quoted context omitted.

This is analogous to different UNIX programs communicating with shmget and a synchronization primitive. It's still a multiprocess model.

At that point, the distinction between threads and processes gets really muddy even when you're not using wasm. clone(2) is just a superset of fork(2) that lets you decide whether to share memory or not (among other resources).

I still think one could use a stackless clone(2) to get rid of the TLB flush when using threaded open(2). It would need to live without using the stack inside the clone however, and that's rather ugly to program.

Re: Multithreading Rust and Wasm

#45
I'm extremely bullish about Rust riding wasm the same way Go rode the container space. This kind of work is exactly why I feel that way. It's uniquely positioned to take advantage of the benefits of wasm; building faster, safer applications on the browser.

I look forward to the day when the web is Rust, although I guess if you're using Firefox, that's already partly true. :)

Re: Multithreading Rust and Wasm

#46
post #23

The ultimate test would be to see if it is possible to implement an efficient concurrent GC in Rust+WASM. This might require memory fence instructions in WASM.

I thought you didn't have raw stack access in wasm, making efficient concurrent GCs impossible practically in native wasm. Hence the GC work to give a higher level API that can more easily be sandboxed.

It's worth noting that you can, and in general do, create your own stack in the wasm memory space. WebAssembly's native stack can only handle 32 and 64 bit integers and floats, so local variables are more like registers
Post reply on HN