相关文章推荐
豪气的荒野  ·  WebSocket.ReceiveAsync ...·  1 月前    · 
斯文的烤面包  ·  解决 CefSharp ...·  3 月前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

You can create a WebAssembly shared memory instance via the JavaScript API:

const memory = new WebAssembly.Memory({
  initial: 80,
  maximum: 80,
  shared: true

You can then send this memory instance to a Web Worker via postMessage:

const worker = new Worker("worker.js");
worker.postMessage({ memory });

The file worker.js can then create a WebAssembly module using this shared memory instance, allowing it to be shared across module instance in different threads.

For a more complete example, see this blog post:

Faster Fractals with Multi-Threaded WebAssembly Thanks a lot! I have written your posts several times and I was interested to talk you about them. In the worker.js can I use some instructions like what we use for SharedArrayBuffer in JS? And I will be grateful if you introduce me a link to talk you. – user12052616 Jan 20, 2020 at 9:01 I want to increment the content of memory from 0 in a infinite loop and read its value in the code whenever I want. And my question is: how to implement this part of code in the worker and how to read it? Thanks. – user12052616 Jan 20, 2020 at 9:32

Thanks for contributing an answer to Stack Overflow!

But avoid

To learn more, see our tips on writing great answers.