Rust / wasm multi threading

Is Multithreading in WebAssembly still state of the art for Rust/wasm multi threading?

In particular, if I am reading that comment correctly:

  • it is possible to have multiple OS threads via web-workers
  • sharing between the threads is limited (i.e. message passing style)

What I would like to do is something closer to Linux style threading -- i.e. a shared memory space that all threads run from.

=====

The particular application I am working on is a small VM that runs 'M' green threads on 'N' OS threads. To the best of my knowledge, without dividing the VM threads into 'batches' and ensuring they have separate heaps, there is no wa yto do this in a 'message passing style' -- and that we need a shared address space with multiple threads.

Shared memory is coming back:

I don't know how far js-sys is, but I expect that you can spawn threads soon-ish.

2 Likes

I am not familiar with this. Here is my current understanding from reading that link:

  1. To make this work, we need both browser/webassembly support of SharedArrayBuffer and rustc/js-sys/web-sys support.

  2. Firefox 79 has SharedArrayBuffer support. Chrome support is in development.

  3. Status or rustc/js-sys/web-sys support is unknown.

Is the above understanding correct?

Browser support is unavoidable. Without it, it just doesn't run.

Without js-sys support, you probably have to write some JS to spawn two threads using the same memory.

rustc is not involved.

2 Likes